53 lines
929 B
C++
53 lines
929 B
C++
|
#include "irdeque.h"
|
||
|
|
||
|
bool irdeque::addToIRDequeLeft(int id) {
|
||
|
if(in_irdeque(id)) {
|
||
|
return false;
|
||
|
}
|
||
|
l.insertHead(id);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool irdeque::removeFromIRDequeLeft() {
|
||
|
int id = l.at(l.size() - 1);
|
||
|
l.remove(id);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool irdeque::removeFromIRDequeRight() {
|
||
|
int id = l.at(0);
|
||
|
l.remove(id);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
int irdeque::showTopOfIRDequeLeft() {
|
||
|
if(l.size() == 0) {
|
||
|
return -1;
|
||
|
}
|
||
|
int left = l.at(l.size() - 1);
|
||
|
return left;
|
||
|
}
|
||
|
|
||
|
int irdeque::showTopOfIRDequeRight() {
|
||
|
if(l.size() == 0) {
|
||
|
return -1;
|
||
|
}
|
||
|
int right = l.at(0);
|
||
|
return right;
|
||
|
}
|
||
|
|
||
|
int irdeque::showSizeOfIRDeque() {
|
||
|
return l.size();
|
||
|
}
|
||
|
|
||
|
bool irdeque::in_irdeque(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;
|
||
|
}
|