Determining whether the operation list with a list of common ring

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Nash_Cyk/article/details/79083166

The idea is a step 1, a step is 2, so if there is a ring buckle ring chain there will be a phenomenon!

bool CheckListIsCircle(LIST_NODE * m_pHead)
{
    LIST_NODE * m_pFrist = m_pHead;
    LIST_NODE * m_pSecond = m_pHead;

    while(m_pSecond!= NULL && m_pSecond->next != NULL )
    {
        m_pFrist = m_pFrist->next;
        m_pSecond = m_pSecond->next->next;
        if (m_pFrist == m_pSecond)
        {
            return true;
        }
    }
    return false;   
}

Guess you like

Origin blog.csdn.net/Nash_Cyk/article/details/79083166