What's the best way to detect a loop in a linked list?
Sigiloso
I'll rather make a doubly link list first (easy to navigate both directions) struct node { var element; node* next; node* previous; } *head; //declare head pointer write stub method to set it bool isloop(LList) { if (!isempty(LList) //check if list is not empty { Node *pointer=head; // define pointer setting to head while(pointer.next -> null) //iterate through list from head to tail { if(pointer.next == pointer.previous) //its a loop : next is pointing to previous return true; } return false; // return false if condition is not meat } //end if } //end while } // end method