-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeque.cpp
More file actions
96 lines (90 loc) · 1.57 KB
/
Copy pathdeque.cpp
File metadata and controls
96 lines (90 loc) · 1.57 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
#include "deque.h"
#include "pumpbadge.h"
Deque::Deque(){
head = NULL;
tail = NULL;
for(int i=0; i < QUEUE_LENGTH; i++){
node *temp = (node *) malloc(sizeof(node));
temp->prev = NULL;
temp->next = NULL;
//initialize the list with just black blocks
memset(temp->blocks, BG_COLOR, LINE_WIDTH);
insertTail(temp);
}
}
void Deque::insertHead(node *in){
if(in != NULL){
if(head==NULL){
head = in;
tail = in;
}
else{
in->next = head;
head->prev = in;
head = in;
}
}
}
void Deque::insertTail(node *in){
if(in != NULL){
if(tail==NULL){
head = in;
tail = in;
}
else{
in->prev = tail;
tail->next = in;
tail = in;
}
}
}
node *Deque::deleteHead(){
if(head == NULL){
return NULL;
}
else{
node *temp = head;
head = head->next;
if(head==NULL){
tail=NULL;
}
else{
head->prev = NULL;
}
return temp;
}
}
node *Deque::deleteTail(){
if(tail==NULL){
return NULL;
}
else{
node *temp = tail;
tail = tail->prev;
if(tail==NULL){
head=NULL;
}
else{
tail->next = NULL;
}
return temp;
}
}
bool Deque::isHead(node *in){
return in != NULL && in->prev == NULL ;
}
bool Deque::isTail(node *in){
return in != NULL && in->next == NULL;
}
void Deque::print(){
node *temp = head;
while(temp!=NULL){
//print node contents
for(int i=0;i<LINE_WIDTH;i++){
Serial.print(temp->blocks[i],HEX);Serial.print(" ");
}
delay(5);
Serial.println();
temp = temp->next;
}
}