-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·54 lines (43 loc) · 1.15 KB
/
main.c
File metadata and controls
executable file
·54 lines (43 loc) · 1.15 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
#include <stdio.h>
#include <stdlib.h>
#include "linked_list.h"
int main(void)
{
node *head = NULL;
/*Insert at the first*/
head = insert_first(head, 10);
head = insert_first(head, 5);
head = insert_first(head, 2);
head = insert_first(head, 1);
/*Insert at the end*/
head = insert_end(head, 20);
head = insert_end(head, 30);
/*Insert at the specific postion*/
head = insert_pos(head, -2, 0);
head = insert_pos(head, 40, 7);
head = insert_pos(head, 15, 5);
head = insert_pos(head, 35, 8);
/*Delete at the first*/
head = delete_first(head);
head = delete_first(head);
head = delete_first(head);
/*Delete at the end*/
head = delete_end(head);
head = delete_end(head);
// /*Insert at the specific postion*/
head = delete_pos(head, 2);
head = delete_pos(head, 0);
/*Print doubly linked list nodes*/
print_node(head);
/*Print number of nodes*/
int n = count_nodes(head);
if (n == 0)
printf("Doubly linked list is empty\n");
else
{
printf("Number of nodes = %d\n", n);
}
/*Free nodes*/
free_nodes(head);
return 0;
}