数据结构做得少,被坑得外焦里嫩~
是否有环,代码量如此低……
bool IfCircle(LinkList *root)
{
/*
追赶式验证是否存在环
*/
LinkList *fast=root;
LinkList *slow=root;
while(fast && slow)
{
fast=fast->p_next;
fast=fast->p_next;
if(fast==slow)
return true;
slow=slow->p_next;
}
return false;
}
附加一道数学题吧
int test3(int x)
{
int count=0;
while(x)
{
x=x&(x-1);
count++;
}
return count;
}
转成二进制有多少个1count就有多少