-
Notifications
You must be signed in to change notification settings - Fork 2
/
queue.c
69 lines (59 loc) · 1.14 KB
/
queue.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
#include <iostream>
using namespace std;
int top=-1,size;
void push(int arr[]){
if(top==size-1)
cout<<"Stack Overflow\n";
else{
cout<<"Enter the value\n";
int val;
cin>>val;
arr[++top]=val;
}
}
void pop(int arr[]){
if(top==-1)
cout<<"Underflow\n";
else{
cout<<arr[0]<<endl;
for(int i=0;i<top;i++)
arr[i]=arr[i+1];
top-=1;
}
}
void display(int arr[]){
for(int i=0;i<=top;i++)
cout<<arr[i]<<" ";
cout<<endl;
}
int main()
{
cout<<"Enter the size of the array\n";
int sizes;
cin>>sizes;
size=sizes;
bool loop=true;
int arr[size];
while(loop){
cout<<"1. Insertion\t2. Deletion\t3. Display\t4. Exit\n";
int ch;
cin>>ch;
switch(ch){
case 1:
push(arr);
break;
case 2:
pop(arr);
break;
case 3:
display(arr);
break;
case 4:
loop=false;
break;
default:
cout<<"Enter the right choice";
}
}
return 0;
}