+ 3
Can anyone help me out of this infinite loop??
3 RĂ©ponses
+ 3
An option would be to take note of the node you begin to access, then on each iteration, check if the address of the next node you are accessing is equivalent to that one you first accessed. Just piggybacking off Carrie's suggestion: In this case the unique ID is the content of the node pointer.
void Node :: printlist(Node *node){
Node* begin = node;
while(node != NULL){
cout<<node->data<<" <---> ";
node = node->next;
if (node == begin)
break;
}
cout<<"END"<<endl;
}
+ 1
You probably need a unique id of some sort to identify each node since it's circular list, meaning the last node connects to the first node and therefore no NULL node exists. You then can use check their unique id to stop the iteration.
+ 1
Thanks a lot dear sire..... Now if any body can help me with addAfter(đ)