GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 110 of 190    Print  
Find nth node from end of a singly linked list

  
Total Answers and Comments: 2 Last Update: February 16, 2007     Asked by: smart_coder 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 09, 2007 23:07:08   #1  
Abi George Ullattil        

RE: Find nth node from end of a singly linked list
struct node{ int data; node* next;};// This function will return the point to the nth node from the end.// If the number of links is less the value n, then it returns the start of the linked list// If the linked list has only one node, then it returns the link to the end node// (which again is the start node for that linked list)node* findNthNodeFromEnd(node *end,int n){ if(!end || n<0) return NULL; else if(n == 0) return end; char *p; node *curr,*prev = end; int i = 0; curr = prev - 1; p = (char*)curr; while(p != 0) { if(curr->next == prev) { ++i; if(i == n) return curr; prev = curr; } --p; curr = (node*)p; } return prev;}The explanation for this one should be easily understandable i guess. If you have doubt mail me.
 
Is this answer useful? Yes | No
February 16, 2007 00:07:18   #2  
Apoorv        

RE: Find nth node from end of a singly linked list
A simple way out would be..Use two pointers..*traverse and *nth_positionboth initialised to null..While you traverse to the end of the list using *traverse,let *nth_position follow only after n iterations..So at all times, *nth_position will be n places behind *traverse..Continue till traverse reaches end of list..If list has less than n nodes, nth_position points to null.
 
Is this answer useful? Yes | No

 Related Questions

Runtime type identification (RTTI) lets you find the dynamic type of an object when you have only a pointer or a reference to the base type. RTTI is the official way in standard C++ to discover the type 
Latest Answer : We can only assign a derived object to a base object pointer and a base class member to a derived class member pointer. ...

Latest Answer : A simple way out would be..Use two pointers..*traverse and *nth_positionboth initialised to null..While you traverse to the end of the list using *traverse,let *nth_position follow only after n iterations..So at all times, *nth_position will be n places ...

Write a program to concatenate two circular linked lists into a single circular list. 
Latest Answer : Hi It is very simple.Get the Node values from first Circular list and stored in one temp. array.You can keep track of repeated values by checking and comparing each value and then put into array.Now you can add all this array values into second link list. ...

Hi I very recently did the C++ online Quiz and was surprised to find that my answer (1) to the following question (below) was incorrect. Is there something I am missing here, or is the answer incorrect. 
Latest Answer : gpuchtel's answer makes sense to me. The fact that size of the derived class object is sum of size of all the public and private members of base class and derived class corroborates the argument. ...

What is the most efficient way to reverse a linklist? 
Latest Answer : struct node{    int iData;    struct node *iNext;};typedef struct node Node;///////////////////////////////////////////////////Node * ReverseList(Node *aHead){    Node *prev;    Node *cur;   ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape