-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path10. Queue.cpp
109 lines (105 loc) · 2.35 KB
/
10. Queue.cpp
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
#include <iostream>
using namespace std;
#define size 10
template<class T>
class Queue{
public:
int front;
int rear;
T Q[10];
Queue() {
front = -1;
rear = -1;
}
void enqueue(T x) {
if(rear == size-1)
{
cout << "Queue Overflow!!" << endl;
}
else
{
rear++;
Q[rear] = x;
}
}
T dequeue() {
int x = -1;
if (front == rear)
{
cout << "Queue Underflow!!" << endl;
}
else
{
front++;
x = Q[front];
}
return x;
}
void display() {
cout<<"The queue elements are: "<<endl;
for (int i=front+1; i<=rear; i++)
cout << Q[i]<< " ";
cout << endl;
}
};
int main(){
Queue<int> a;
Queue<double> b;
int ch,x;
double y;
START :
cout<<"\nQueue Using Template function:-"<<endl;
cout<<"1.Integer queue"<<endl;
cout<<"2.Double queue"<<endl;
cout<<"3.Exit"<<endl;
cout<<"Enter your choice: ";
cin>>ch;
if(ch == 1){
while(true){
cout<<"\nInteger Queue :-"<<endl;
cout<<"1.Insert"<<endl;
cout<<"2.Delete"<<endl;
cout<<"3.Display"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter your choice: ";
cin>>ch;
switch(ch){
case 1: cout<<"Enter the element to be inserted: ";
cin>>x;
a.enqueue(x);
break;
case 2: a.dequeue();
break;
case 3: a.display();
break;
default : goto START;
}
}
}
else if (ch==2)
{
while(true){
cout<<"\nDouble Queue :-"<<endl;
cout<<"1.Insert"<<endl;
cout<<"2.Delete"<<endl;
cout<<"3.Display"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter your choice: ";
cin>>ch;
switch(ch){
case 1: cout<<"Enter the element to be inserted: ";
cin>>y;
b.enqueue(y);
break;
case 2: b.dequeue();
break;
case 3: b.display();
break;
default : goto START;
}
}
}
else{
exit(0);
}
}