-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
87 lines (69 loc) · 1.33 KB
/
Copy pathqueue.cpp
File metadata and controls
87 lines (69 loc) · 1.33 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
#include<stdio.h>
#include<stdlib.h>
#define size 10
int front=-1;
int rear=-1;
void insert(),del(),display();
int q[size],choice,element,opt;
int main()
{
do
{
printf("\n MENU");
printf("\n 1.Insert a element\n2.Delete a element\n3.Display the queue\n4.Exit");
printf("\n enter your option:");
scanf("%d",&choice);
switch(choice)
{
case 1:insert();break;
case 2:del();break;
case 3:display();break;
case 4:exit(0);
}
printf("\n Do you want to continue(1/0):");
scanf("%d",&opt);
}while(opt==1);
return 0;
}
void insert()
{
printf("\n Enter the element to be added:");
scanf("%d",&element);
if(rear<size-1)
{
q[++rear]=element;
if(front==-1)
front++;
printf("\n Element is added to queue sucessfully");
}
else
printf("\n Queue has fully filled");
}
void display()
{
int i;
if(front!=-1)
{
printf("\n The elements in the queue are:");
for(i=0;i<=rear;i++)
printf("\t %d",q[i]);
}
else
printf("\n No elements in queue");
}
void del()
{
int i;
if(front!=-1)
{
printf("\n element deleted is:%d",q[0]);
for(i=0;i<=rear;i++)
q[i]=q[i+1];
rear--;
if(rear==-1)
front--;
printf("\n Element deleted sucessfully");
}
else
printf("\n No elements in queue");
}