|
-
September 25th, 2012, 06:26 PM
#11
Re: How to find whether a linked list is a circular linked list
I know that I am digging up an old post, but would this also work?
bool circleFound(Node* headNode)
{
bool circleFound = false;
hash_map <Node*,int> hashedNodes;
Node * currNode = headNode;
while(currNode)
{
if (hashedNodes[currNode] > 0)
{
circleFound = true;
break;
}
hashedNodes[currNode] = 1;
currNode = currNode->next;
}
return circleFound;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|