struct LinkedListNode
{
int data;
LinkedListNode* next;
};
bool IsCircle(LinkedListNode* head)
{
if (head == NULL || head->next)
{
return false;
}
LinkedListNode* p = head;
LinkedListNode* q = head;
while (p != NULL && q != NULL)
{
p = p->next;
q = q->next;
if (q != NULL)
{
q = q->next;
}
if (p == q)
{
return true;
}
}
return false;
}