Algorithm Summary:

Determine whether a Nodelist contains circle

1.The Nodelist has no node,return 0

2.The Nodelist has one node and the next field point to NULL return false

3.The Nodelist has more than one Nodes(at least two nodes)

 1)define two point ,p1 and p2,initially both point to head of the list;

 2)Move p1 one step and p2 two steps each time,if the list has circle,p1 and p2 will point to the same node after several steps.

 3)if p2 next field point to NULL after several steps,it indicates that there is no circle in the list.

Implement Code

Code

posted on 2009-04-21 13:41  Evilbaniry  阅读(218)  评论(0编辑  收藏  举报