-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.queue_list.c
More file actions
133 lines (122 loc) · 1.63 KB
/
4.queue_list.c
File metadata and controls
133 lines (122 loc) · 1.63 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//Queue Implementation using Linked list
#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
}*front,*rear;
void insert()
{
struct node *np;
np=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the no. to be inserted : \n");
scanf("%d",&np->data);
np->next=NULL;
if(front==NULL)
{
front=np;
rear=np;
}
else
{
rear->next=np;
rear=np;
}
}
void delete()
{
int item;
if(front==NULL)
printf("\n Queue is empty\n");
else
{
item=front->data;
printf("\nThe item deleted is %d",item);
front=front->next;
}
}
void display()
{
struct node *temp;
temp=front;
if(front==NULL)
printf("\nQueue empty\n");
else
{
printf("The queue contains : ");
while(temp!=NULL)
{
printf("\t%d",temp->data);
temp=temp->next;
}
}
}
void main()
{
int c,n;
do
{
printf("\nEnter your choice\n1.Enqueue\n2.Dequeue\n3.Display\n4.exit\n");
scanf("%d",&c);
switch(c)
{
case 1 : insert();
break;
case 2 : delete();
break;
case 3 : display();
break;
case 4 : exit(0);
default : printf("Invalid Entry");
}
}
while(1);
} //End of Program
/*
OUTPUT
---------------
Enter your choice
1.Enqueue
2.Dequeue
3.Display
4.exit
1
Enter the no. to be inserted :
12
Enter your choice
1.Enqueue
2.Dequeue
3.Display
4.exit
1
Enter the no. to be inserted :
36
Enter your choice
1.Enqueue
2.Dequeue
3.Display
4.exit
3
The queue contains : 12 36
Enter your choice
1.Enqueue
2.Dequeue
3.Display
4.exit
2
The item deleted is 12
Enter your choice
1.Enqueue
2.Dequeue
3.Display
4.exit
3
The queue contains : 36
Enter your choice
1.Enqueue
2.Dequeue
3.Display
4.exit
4
*/