-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2_is_looping.c
33 lines (30 loc) · 1.16 KB
/
2_is_looping.c
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
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 2_is_looping.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qpeng <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/04 02:09:14 by qpeng #+# #+# */
/* Updated: 2018/10/04 02:09:17 by qpeng ### ########.fr */
/* */
/* ************************************************************************** */
typedef struct s_node {
int value;
struct s_node *next;
} Node;
/* works but seems too naive*/
int is_looping(Node* node) {
Node* i = node;
Node* j = node;
while (i && j)
{
i = i->next;
j = j->next;
if (j)
j = j->next;
if (i && j && i == j)
return (1);
}
return (0);
}