Skip to content

Instantly share code, notes, and snippets.

@Se7soz
Created January 15, 2014 11:35
Show Gist options
  • Select an option

  • Save Se7soz/8434694 to your computer and use it in GitHub Desktop.

Select an option

Save Se7soz/8434694 to your computer and use it in GitHub Desktop.
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
#include "list.h" // See problem #8
node* getLoopStart(node* lst) {
node *lnk1 = lst, *lnk2 = lst;
while(lnk2->nxt) {
lnk1 = lnk1->nxt;
lnk2 = lnk2->nxt->nxt;
if(lnk2 == NULL) return NULL;
if(lnk1 == lnk2)
break;
}
if(lnk2->nxt == NULL)
return NULL;
lnk1 = lst;
while(lnk1 != lnk2) {
lnk1 = lnk1->nxt;
lnk2 = lnk2->nxt;
}
return lnk1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment