You are viewing a single comment's thread. Return to all comments →
I did something almost the same, just with a Vector. Here's my implementation:
bool has_cycle(Node* head) { vector<Node*> visited; while (head != NULL) { for(int i = 0; i < visited.size(); ++i) if(head == visited[i]) return true; visited.push_back(head); head = head->next; } return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
I did something almost the same, just with a Vector. Here's my implementation: