Re: [algogeeks] find nth node frm the last
thanku. yes i got it... Seriously nice xplanatin... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find nth node frm the last
ya first initialise first pointer to list. and move the other pointer n nodes. so when the second pointer reaches the last node.the first pointer which is n nodes from second ptr will be in its final position -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find nth node frm the last
its like u have to remain behind one of your friends exactly 10 min... You let him go and keep watching your clock...as soon as it is 10 mins u start walking with the same pace and stop as soon as ur frnd calls u to say its dead end.. On Mon, Aug 8, 2011 at 8:34 PM, sagar pareek wrote: > very good explanation aditi > > > On Mon, Aug 8, 2011 at 8:15 PM, aditi garg wrote: > >> lets say u have 10 nodes 1->2->3->4->5->6->7->8->9->10 >> and u have to find 6th node from the end >> what this code is doing is its taking two pointers,current and >> behind...its frst moving current to 6 places...now current reaches to the >> 6th node after the frst loop...now u strt the second pointer ie behind from >> head and move both current and head until current reaches nullso if u c >> in this example current is pointing to 6th node right now it will move 4 >> places and reach the end and in the mean time behind will reach the 4th >> node...hence finally behind points to 4th node whch is 6th node from the >> end...i hope u get it... >> >> On Mon, Aug 8, 2011 at 8:08 PM, sukran dhawan wrote: >> >>> struct node * fun(struct node * list,int n) >>> >>> >>> >>> On Mon, Aug 8, 2011 at 8:06 PM, jagrati verma < >>> jagrativermamn...@gmail.com> wrote: >>> hw is it possible frm this code ???/ Node * findNToLastNode( Node *head, int N ) { int i = 0; Node *current, *behind; current = head; for( i = 0; i < N; i++ ) { if( current->next ) { current = current->next; } else { return NULL; // Length of the list is less than N } } behind = head; while( current->next ) { current = current->next; behind = behind->next; } return behind; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Aditi Garg >> Undergraduate Student >> Electronics & Communication Divison >> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY >> Sector 3, Dwarka >> New Delhi >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > **Regards > SAGAR PAREEK > COMPUTER SCIENCE AND ENGINEERING > NIT ALLAHABAD > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find nth node frm the last
very good explanation aditi On Mon, Aug 8, 2011 at 8:15 PM, aditi garg wrote: > lets say u have 10 nodes 1->2->3->4->5->6->7->8->9->10 > and u have to find 6th node from the end > what this code is doing is its taking two pointers,current and > behind...its frst moving current to 6 places...now current reaches to the > 6th node after the frst loop...now u strt the second pointer ie behind from > head and move both current and head until current reaches nullso if u c > in this example current is pointing to 6th node right now it will move 4 > places and reach the end and in the mean time behind will reach the 4th > node...hence finally behind points to 4th node whch is 6th node from the > end...i hope u get it... > > On Mon, Aug 8, 2011 at 8:08 PM, sukran dhawan wrote: > >> struct node * fun(struct node * list,int n) >> >> >> >> On Mon, Aug 8, 2011 at 8:06 PM, jagrati verma < >> jagrativermamn...@gmail.com> wrote: >> >>> hw is it possible frm this code ???/ >>> >>> >>> >>> >>> Node * findNToLastNode( Node *head, int N ) >>> { >>>int i = 0; >>>Node *current, *behind; >>>current = head; >>>for( i = 0; i < N; i++ ) { >>>if( current->next ) { >>>current = current->next; >>>} else { >>>return NULL; // Length of the list is less >>> than N >>>} >>>} >>> >>>behind = head; >>>while( current->next ) { >>>current = current->next; >>>behind = behind->next; >>>} >>> >>>return behind; >>> } >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Aditi Garg > Undergraduate Student > Electronics & Communication Divison > NETAJI SUBHAS INSTITUTE OF TECHNOLOGY > Sector 3, Dwarka > New Delhi > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find nth node frm the last
lets say u have 10 nodes 1->2->3->4->5->6->7->8->9->10 and u have to find 6th node from the end what this code is doing is its taking two pointers,current and behind...its frst moving current to 6 places...now current reaches to the 6th node after the frst loop...now u strt the second pointer ie behind from head and move both current and head until current reaches nullso if u c in this example current is pointing to 6th node right now it will move 4 places and reach the end and in the mean time behind will reach the 4th node...hence finally behind points to 4th node whch is 6th node from the end...i hope u get it... On Mon, Aug 8, 2011 at 8:08 PM, sukran dhawan wrote: > struct node * fun(struct node * list,int n) > > > > On Mon, Aug 8, 2011 at 8:06 PM, jagrati verma > wrote: > >> hw is it possible frm this code ???/ >> >> >> >> >> Node * findNToLastNode( Node *head, int N ) >> { >>int i = 0; >>Node *current, *behind; >>current = head; >>for( i = 0; i < N; i++ ) { >>if( current->next ) { >>current = current->next; >>} else { >>return NULL; // Length of the list is less >> than N >>} >>} >> >>behind = head; >>while( current->next ) { >>current = current->next; >>behind = behind->next; >>} >> >>return behind; >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Aditi Garg Undergraduate Student Electronics & Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find nth node frm the last
On Mon, Aug 8, 2011 at 8:08 PM, sukran dhawan wrote: > struct node * fun(struct node * list,int n) { struct node *p,*q ; p = q = list; int n1 = 1; while(p->next != NULL) { if(n1 next; } else { p=p->next; q = q->next; } } return q; } > > > > On Mon, Aug 8, 2011 at 8:06 PM, jagrati verma > wrote: > >> hw is it possible frm this code ???/ >> >> >> >> >> Node * findNToLastNode( Node *head, int N ) >> { >>int i = 0; >>Node *current, *behind; >>current = head; >>for( i = 0; i < N; i++ ) { >>if( current->next ) { >>current = current->next; >>} else { >>return NULL; // Length of the list is less >> than N >>} >>} >> >>behind = head; >>while( current->next ) { >>current = current->next; >>behind = behind->next; >>} >> >>return behind; >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find nth node frm the last
struct node * fun(struct node * list,int n) On Mon, Aug 8, 2011 at 8:06 PM, jagrati verma wrote: > hw is it possible frm this code ???/ > > > > > Node * findNToLastNode( Node *head, int N ) > { >int i = 0; >Node *current, *behind; >current = head; >for( i = 0; i < N; i++ ) { >if( current->next ) { >current = current->next; >} else { >return NULL; // Length of the list is less than > N >} >} > >behind = head; >while( current->next ) { >current = current->next; >behind = behind->next; >} > >return behind; > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] find nth node frm the last
hw is it possible frm this code ???/ Node * findNToLastNode( Node *head, int N ) { int i = 0; Node *current, *behind; current = head; for( i = 0; i < N; i++ ) { if( current->next ) { current = current->next; } else { return NULL; // Length of the list is less than N } } behind = head; while( current->next ) { current = current->next; behind = behind->next; } return behind; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.