Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. node* FindBeginning(node* head) {
  2. node* p1 = head;
  3. node* p2 = head;
  4. while (p2->next != nullptr) {
  5. if (p1 == p2) break;
  6. p1 = p1->next;
  7. p2 = p2->next->next;
  8. }
  9. if (p2->next == nullptr) return nullptr; // there is no loop
  10.  
  11. p1 = head;
  12. while (p1 != p2) {
  13. p1 = p1->next;
  14. p2 = p2->next;
  15. }
  16. return p1;
  17.  
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement