bool IsCircular(Node* head)
{
bool circleFound = false;
bool tailFound = false;
if (head && head->next)
{
Node* slower = head;
Node* faster = head;
do
{
slower = slower->next;
faster = faster->next->next;
tailFound = ! (faster && faster->next);
if ( ! tailFound )
{
circleFound = (slower == faster || slower == faster->next);
}
}
while ( ! tailFound && ! circleFound)
}
return ( circleFound );
}
{
bool circleFound = false;
bool tailFound = false;
if (head && head->next)
{
Node* slower = head;
Node* faster = head;
do
{
slower = slower->next;
faster = faster->next->next;
tailFound = ! (faster && faster->next);
if ( ! tailFound )
{
circleFound = (slower == faster || slower == faster->next);
}
}
while ( ! tailFound && ! circleFound)
}
return ( circleFound );
}
No comments:
Post a Comment