forked from hacktoberfest17/programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdequeue.h
More file actions
61 lines (52 loc) · 1.04 KB
/
dequeue.h
File metadata and controls
61 lines (52 loc) · 1.04 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
#include <iostream>
using namespace std;
class Node {
public:
Node(unsigned short s)
{
Node *p_next = nullptr;
Node *p_prev = nullptr;
value = s;
}
Node *p_next = nullptr;
Node *p_prev = nullptr;
unsigned short value = 0;
};
class Dequeue {
public:
Dequeue(Node* n) {
head = n;
tail = n;
}
void PushFront(Node* n){
n->p_prev = head;
head = n;
n->p_next = nullptr;
}
void PushBack(Node* n){
n->p_next = tail;
tail = n;
n->p_prev = nullptr;
}
void PopFront(){
Node *temp = head;
head = head->p_prev;
head->p_next = nullptr;
delete temp;
}
void PopBack(){
Node *temp = tail;
tail = tail->p_next;
tail->p_prev = nullptr;
delete temp;
}
void PrintValueAtFront(){
cout << head->value << endl;
}
void PrintValueAtBack(){
cout << tail->value << endl;
}
private:
Node *head = nullptr;
Node *tail = nullptr;
};