-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab3_3.c
75 lines (62 loc) · 1.42 KB
/
lab3_3.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*WAP using switch cases to perform the following operations.
i) create a linked list,
ii) display its element
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
struct node {
int info;
struct node *link;
};
void insert();
void display();
typedef struct node DATA_NODE;
DATA_NODE *head_node, *first_node, *temp_node = 0, *prev_node, next_node;
int data;
int main() {
int option = 0;
while (option < 5) {
printf("\nOptions\n");
printf("1 : Insert into Linked List \n");
printf("2 : Display Linked List\n");
printf("Others : leave()\n");
printf("Enter your option: \n");
scanf("%d", &option);
switch (option) {
case 1:
insert();
break;
case 2:
display();
break;
default:
break;
}
}
return 0;
}
void insert() {
printf("\nEnter Element for Insert Linked List : \n");
scanf("%d", &data);
temp_node = (DATA_NODE *) malloc(sizeof (DATA_NODE));
temp_node->info = data;
if (first_node == 0) {
first_node = temp_node;
} else {
head_node->link = temp_node;
}
temp_node->link = 0;
head_node = temp_node;
fflush(stdin);
}
void display() {
int count = 0;
temp_node = first_node;
printf("\nDisplay Linked List : \n");
while (temp_node != 0) {
printf("%d ", temp_node->info);
count++;
temp_node = temp_node->link;
}
}