typedef struct Node
{
    int Data;
    Node *Next;
};
Node *ReverseList(Node *pHead)
{
    Node *pReverseHead = NULL;
    while (pHead != NULL)
    {
        Node *pTmp = pHead;
        pHead = pHead->Next;
        pTmp->Next = pReverseHead;
        pReverseHead = pTmp;
    }
    return pReverseHead;
}
bool hasCircle(Node *pHead)
{
    Node *pSlow = pHead;
    Node *pFast = pHead;
    while (pSlow && pFast && (pFast = pFast->Next) && pFast != pSlow)
    {
        pSlow = pSlow->Next;
        pFast = pFast->Next;
    }
    return pFast != NULL;
}

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *