-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-main.c
53 lines (45 loc) · 1.08 KB
/
10-main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lists.h"
/**
* main - check the code
*
* Return: Always 0.
*/
int main(void)
{
listint_t *head;
listint_t *current;
listint_t *temp;
int i;
head = NULL;
add_nodeint(&head, 0);
add_nodeint(&head, 1);
add_nodeint(&head, 2);
add_nodeint(&head, 3);
add_nodeint(&head, 4);
add_nodeint(&head, 98);
add_nodeint(&head, 402);
add_nodeint(&head, 1024);
print_listint(head);
if (check_cycle(head) == 0)
printf("Linked list has no cycle\n");
else if (check_cycle(head) == 1)
printf("Linked list has a cycle\n");
current = head;
for (i = 0; i < 4; i++)
current = current->next;
temp = current->next;
current->next = head;
if (check_cycle(head) == 0)
printf("Linked list has no cycle\n");
else if (check_cycle(head) == 1)
printf("Linked list has a cycle\n");
current = head;
for (i = 0; i < 4; i++)
current = current->next;
current->next = temp;
free_listint(head);
return (0);
}