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

38 lines
625 B
C++

#include "stack.h"
bool stack::addToStack(int id) {
if(in_stack(id)) {
return false;
}
l.insertHead(id);
return true;
}
int stack::removeFromStack() {
int id = l.at(0);
l.remove(id);
return false;
}
int stack::showTopOfStack() {
if(l.size() == 0)
return -1;
int top = l.at(0);
return top;
}
int stack::showSizeOfStack() {
return l.size();
}
bool stack::in_stack(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;
}