A slight change in above code: make it while(cur && cur->next) ^^ other wise the code will crash at last element in a prefect list, with no loop.
On 18 August 2011 07:36, Dipankar Patro <[email protected]> wrote: > I have come up with this: > - Use only one pointer, NODE *cur > - initialize cur to headref > > - The main loop: > while (cur) > { > if(cur->next->prev != cur) > break; > cur=cur->next; > } > return cur; > > ^^ I think the code is self explanatory. It just uses the fact that at > loop, the prev of next to current won't be current. > e.g. A<->B<->C<->D<->E<->F->C > Though F is pointing to C, C won't be pointing back to F as the prev of C > is pointing to B. > Complexity: O(n) > > On 18 August 2011 04:45, payal gupta <[email protected]> wrote: > >> ys...i guess i misinterpreted..the question.. >> ma fault... >> >> >> On Thu, Aug 18, 2011 at 4:27 AM, Brijesh Upadhyay < >> [email protected]> wrote: >> >>> At the node from where the loop just started.. anyway we could not use >>> that logic , coz it isnt circular linked list! >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. >>> >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > > ___________________________________________________________________________________________________________ > > Please do not print this e-mail until urgent requirement. Go Green!! > Save Papers <=> Save Trees > -- ___________________________________________________________________________________________________________ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers <=> Save Trees -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
