-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeque.cpp
More file actions
47 lines (39 loc) · 935 Bytes
/
Deque.cpp
File metadata and controls
47 lines (39 loc) · 935 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
#include "Deque.hpp"
// Check if the deque is empty or not
bool Deque::isEmpty() const{
return DList.isEmpty();
}
// Return the first element
const Elem& Deque::front(){
return DList.front();
}
// Return the last element
const Elem& Deque::back(){
return DList.back();
}
// Return the number of items in the deque
int Deque::size() const{
return n;
}
// Insert a new element at the beginning of the deque
void Deque::insertFront(const Elem& element){
DList.addFront(element);
n++;
}
// Insert a new element at the end of the deque
void Deque::insertBack(const Elem& element){
DList.addBack(element);
n++;
}
// Remove the first element of the deque
void Deque::removeFront(){
if(isEmpty()){ throw("Empty deque");}
DList.removeFront();
n--;
}
// Remove the last element of the deque
void Deque::removeBack(){
if(isEmpty()){ throw("Empty deque");}
DList.removeBack();
n--;
}