判断一个单向链表是否有环
2015-08-19 11:16
344 查看
struct node
{
struct *next;
};
typedef stuct node Node;
bool getCycle(){
Node* temp1 = head;//(假设head就是这个链表的头)
Node* temp2 = head;
while(head->next!=NULL)
{
temp1 = temp1->next;//步长为1
temp2 = temp2->next->next;//步长为2
if(temp1 == temp2)
return ture;
head=head->next;
}
return false;
}
{
struct *next;
};
typedef stuct node Node;
bool getCycle(){
Node* temp1 = head;//(假设head就是这个链表的头)
Node* temp2 = head;
while(head->next!=NULL)
{
temp1 = temp1->next;//步长为1
temp2 = temp2->next->next;//步长为2
if(temp1 == temp2)
return ture;
head=head->next;
}
return false;
}
相关文章推荐
- 开源全局配置中心XDiamond
- Mysql 5.6.26 zip免安装版配置安装教程
- ios开发判断网络连接及网络异常(ios自学笔记)
- Qt网络获取外网的网络信息
- 生成某一个view的png图片
- VIM C语言函数名高亮
- androidannotations学习笔记
- Unity 2D 英文教程(www.raywenderlich.com)
- Swift——(两)Swift访问元组
- 技巧:在 C/C++中如何构造通用的对象链表
- HDU 1164 Eddy's research I(素数)
- office转html文档在线预览
- BKDR Hash
- codeforces 316 D
- HDU 1827--Summer Holiday【强连通缩点新建图】
- Android Preference的使用
- UIView详解
- 【Python】[面性对象编程] 获取对象信息,实例属性和类属性
- ectouch第十讲 之ecshop中 dwt, lbi 文件详解
- 用jsmooth + inno生成exe并制作简单安装包