struct list list next struct checker list ptr size_t idx bool check_lo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
struct list
{
list* next;
}
struct checker
{
list* ptr;
size_t idx;
}
bool check_loop(list *lst)
{
checker first = {lst, 0};
while(first.ptr->next)
{
first.ptr = first.ptr->next;
++first.idx;
checker control = {lst, 0}
while(control.ptr != first.ptr}
{
++control.idx;
first.ptr = first.ptr->next;
}
if(control.idx < first.idx)
return true;
}
return false;
}