Repository navigation
Expand file tree
/
Copy pathdeque.cpp
More file actions
115 lines (98 loc) · 1.86 KB
/
Copy pathdeque.cpp
File metadata and controls
115 lines (98 loc) · 1.86 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
#include <iostream>
using namespace std;
#define max 5
class deques
{
private:
int arr[max];
int front;
int rear;
public:
deques();
bool empty();
int push_back(int top);
int push_front(int num); ///int pe
void pop_front(); //remove front
void pop_back();
bool isfull();
void display();
};
deques::deques()
{
front = -1;
rear = -1;
}
bool deques::empty()
{
if(front == -1 and rear == -1)
{
return 1;
}
else return 0;
}
bool deques::isfull()
{
if(rear == max - 1)
{
return 1;
}
else return 0;
}
int deques::push_back(int num)
{
rear++;
if(front == -1){ front = 0; }
arr[rear] = num;
return arr[rear] = num;
}
int deques::push_front(int num)
{
if(front == -1)
{
front = 0;
rear = 0;
return arr[rear] = num;;
}
if(front != -1)
{
rear++;
int len = sizeof(arr)/sizeof(arr[0]);
for(int i = 0 ; i < len - 1; i++)
{
arr[i] = arr[i+1];
}
return arr[rear] = num;
}
}
void deques::pop_front()
{
front++;
}
void deques::pop_back()
{
rear--;
}
void deques::display()
{
for(int j = 0; j <= rear; j++)
{
cout << arr[j] << ' ';
}
}
int main()
{
deques q1;
cout << (q1.empty() == true ? "is empty : true\n" : "is empty : false\n");
q1.push_back(10);
cout << "enqueued 10 at back" << endl;
// cout << "front : " << q1.peak() << endl ;
// cout << "back : " << q1.back() << endl << endl;
q1.push_back(20);
cout << "enqueued 20 at back" << endl;
q1.pop_back();
cout << "popped 20 at back" << endl;
q1.push_back(90);
cout << "enqueued 90 at back" << endl;
q1.display();
}
//next make template so i can use it with string too