-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdequeue.cpp
More file actions
84 lines (67 loc) · 1.32 KB
/
dequeue.cpp
File metadata and controls
84 lines (67 loc) · 1.32 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
#include<iostream>
using namespace std;
#define MAX_CAP 3
class Deque{
int front, rear, size, capacity;
int *array = NULL;
public:
Deque(){
array = new int[MAX_CAP];
front = 0;
rear = 0;
size = 0;
capacity = MAX_CAP;
}
void enqueue(int data){
if(size == capacity){
cout<<"Overflow\n";
return;
}
else{
if(size == 0){
array[front] = data;
rear = front;
size = size+1;
}
else{
rear = (rear+1)%capacity;
array[rear] = data;
size = size+1;
}
}
}
void dequeue(){
if(size == 0){
cout<<"Underflow\n";
return;
}
else{
array[front] = 0;
front = (front+1)%capacity;
size = size-1;
}
}
void show(){
if(size==0){
return;
}
for(int i=front; i<=rear; ++i){
cout<<array[i]<<" ";
}
cout<<endl;
}
};
int main(){
Deque q;
//q.show();
//q.dequeue();
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
q.dequeue();
q.dequeue();
q.enqueue(3);
//q.show();
//q.dequeue();
q.show();
}