forked from dharmanshu1921/Daa-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpQueue.cpp
More file actions
56 lines (56 loc) · 799 Bytes
/
impQueue.cpp
File metadata and controls
56 lines (56 loc) · 799 Bytes
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
#include <iostream>
using namespace std;
class Queue{
public:
int rear;
int front;
int * arr;
int size;
Queue(int n){
rear=-1;
front=-1;
arr=new int[n];
size=n;
}
void push(int val){
if(rear>=size){
cout<<"Queue Overflow:"<<endl;
return ;
}
if(front==-1){
front++;
}
rear++;
arr[rear]=val;
}
void pop(){
if(front>rear||front==-1){
cout<<"Queue Underflow"<<endl;
return ;
}
front++;
}
void print(){
if(front>rear||front==-1){
cout<<"Queue Underflow"<<endl;
return ;
}
int k=front;
while(k<=rear){
cout<<arr[k]<<" ";
k++;
}
cout<<endl;
}
};
int main(){
Queue Q(10);
Q.pop();
Q.print();
Q.push(5);
Q.push(10);
Q.print();
Q.pop();
Q.push(15);
Q.print();
}