`
chentingk
  • 浏览: 19055 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

多益笔试题链表是否有环

 
阅读更多

数据结构做得少,被坑得外焦里嫩~

是否有环,代码量如此低……

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就有多少

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics