- bool FixRing(Node * pHead)
- {
- Node * pSlow = pHead ;
- Node * pFast = pHead;
- while ( pFast && pFast -> next ) //如果存在环,不存在p-next=NULL的情况
- {
- pSlow = pSlow -> next;//前进一步
- pFast = pFast -> next -> next;//前进两步
- if ( pSlow == pFast )
- break ;
- }
- return ! (pFast == NULL || pFast -> next == NULL);
- }
判断单链表是否有环
最新推荐文章于 2022-08-09 23:31:45 发布