-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic queue.txt
More file actions
94 lines (90 loc) · 1.83 KB
/
dynamic queue.txt
File metadata and controls
94 lines (90 loc) · 1.83 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h> //NAME-KINGSUK BASAK ROLL NO - CSE2019/027
typedef struct NODE
{
int data;
struct NODE *link;
}
NODE;
NODE *header = NULL;
main()
{
int choice;
while (1)
{
printf("Press (1) to insert element to queue\n");
printf("Press (2) to Delete element from queue\n");
printf("Press (3) to Display all elements of queue\n");
printf("Press (4) to Quit\n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
Insertion();
break;
case 2:
Deletion();
break;
case 3:
Display();
break;
case 4:
exit(0);
default:
printf("Invalid choice:\n");
}
}
return (0);
}
int Insertion()
{
NODE *ptr, *newn;
newn = (NODE *)malloc(sizeof(NODE));
printf("Insert a element in queue : ");
scanf("%d", &newn->data);
newn->link = NULL;
if (header == NULL)
{
header = newn;
}
else
{
ptr = header;
while (ptr->link != NULL)
{
ptr = ptr->link;
}
ptr->link = newn;
}
printf("insertion Done!!!");
}
int Deletion()
{
NODE *ptr;
if (header == NULL)
printf("Queue Underflow\n");
else
{
ptr = header;
header = ptr->link;
free(ptr);
}
printf("Deletion Done!!!\n");
}
int Display()
{
NODE *ptr;
if (header == NULL)
printf("Queue is empty\n");
else
{
printf("Queue is : ");
ptr = header;
while (ptr != NULL)
{
printf("%d ", ptr->data);
ptr = ptr->link;
}
}
printf("\n");
}