-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquetemplate.cpp
More file actions
133 lines (115 loc) · 1.53 KB
/
quetemplate.cpp
File metadata and controls
133 lines (115 loc) · 1.53 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
// QUEUE PROGRAM USING TEMPLATES
//NAME-ABHISHEK KUMAR LABH
//ROLL NO-09/CSE/52
#include<iostream>
using namespace std;
template<class T>
class queue{
private:
int top,MAX;
T *v,j;
public:
queue(int a){
v=new T[a] ;
top=-1;
MAX=a-1;
}
void push(T j){
if(top==MAX){
cout<<"stack is overflow"<<endl;
}
else
{
v[++top]=j;
}
}
void pop(){
if(top==-1){
cout<<"stack is underflow"<<endl;
}
else
{
for(int s=0;s<top;s++)
v[s]=v[s+1];
--top;
}
}
void display(){
for(int s=0;s<=top;s++)
cout<<v[s]<<endl;
}
};
int main(){
int c,n;
queue <int> q1(4);
do{
cout<<"queue"<<endl;
cout<<"1.push into the queue"<<endl;
cout<<"2.pop into the queue"<<endl;
cout<<"3.display"<<endl;
cin>>c;
switch(c)
{
case 1:
cout<<"enter the no:";
int item;
cin>>item;
q1.push(item);
break;
case 2:
q1.pop();
break;
case 3:
q1.display();
break;
default:
cout<<"error:try again"<<endl;
}
cout<<"enter 1 for continue"<<endl;
cin>>n;
}while(n==1);
return 0;
}
/* output
dell@ubuntu:~$ g++ quetemplate.cpp
dell@ubuntu:~$ ./a.out
queue
1.push into the queue
2.pop into the queue
3.display
1
enter the no:34
enter 1 for continue
1
queue
1.push into the queue
2.pop into the queue
3.display
1
enter the no:23
enter 1 for continue
1
queue
1.push into the queue
2.pop into the queue
3.display
3
34
23
enter 1 for continue
1
queue
1.push into the queue
2.pop into the queue
3.display
2
enter 1 for continue
1
queue
1.push into the queue
2.pop into the queue
3.display
3
23
enter 1 for continue
*/