Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- node* FindBeginning(node* head) {
- node* p1 = head;
- node* p2 = head;
- while (p2->next != nullptr) {
- if (p1 == p2) break;
- p1 = p1->next;
- p2 = p2->next->next;
- }
- if (p2->next == nullptr) return nullptr; // there is no loop
- p1 = head;
- while (p1 != p2) {
- p1 = p1->next;
- p2 = p2->next;
- }
- return p1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement