school/cs235/lab05/ordeque.cpp
2016-04-06 20:46:10 -07:00

47 lines
831 B
C++

#include "ordeque.h"
bool ordeque::addToORDequeLeft(int id) {
if(in_ordeque(id)) {
return false;
}
l.insertHead(id);
return true;
}
bool ordeque::addToORDequeRight(int id) {
if(in_ordeque(id)) {
return false;
}
l.insertTail(id);
return true;
}
bool ordeque::removeFromORDequeLeft() {
int id = l.at(l.size() - 1);
l.remove(id);
return true;
}
int ordeque::showTopOfORDequeLeft() {
if(l.size() == 0) {
return -1;
}
int left = l.at(l.size() - 1);
return left;
}
int ordeque::showSizeOfORDeque() {
return l.size();
}
bool ordeque::in_ordeque(int id) {
node* node_ptr = l.head;
while(node_ptr != NULL) {
if(node_ptr->id == id) {
return true;
}
node_ptr = node_ptr->next;
}
return false;
}