-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.c
More file actions
67 lines (58 loc) · 1.11 KB
/
linked_list.c
File metadata and controls
67 lines (58 loc) · 1.11 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int num;
struct node *next;
}node;
void add_node(node *head, int num) {
node * current = head;
while (current->next != NULL) {
current = current->next;
}
current->next = malloc(sizeof(node));
current->next->num = num;
current->next->next = NULL;
}
void ft_printer(node *head)
{
node *tmp = head;
while (tmp != NULL)
{
if (tmp->next == NULL)
printf("%d", tmp->num);
else
printf("%d-", tmp->num);
tmp = tmp->next;
}
printf("\n");
}
void ft_free(node* head)
{
node *tmp;
while (head != NULL)
{
tmp = head;
head = head->next;
free(tmp);
}
}
int main()
{
node *head;
head = malloc(sizeof(node));
head->next= NULL;
head->num=1;
add_node(head, 10);
add_node(head, 20);
add_node(head, 30);
add_node(head, 40);
add_node(head, 50);
add_node(head, 60);
add_node(head, 70);
add_node(head, 80);
add_node(head, 90);
add_node(head, 100);
ft_printer(head);
ft_free(head);
}