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

250 lines
4.9 KiB
C++

#include "station.h"
bool station::addToStation(int car) {
if(current_car == -1 and car > 0 and !s.in_stack(car) and !q.in_queue(car) and !d.in_deque(car) and !ir.in_irdeque(car) and !ord.in_ordeque(car)) {
current_car = car;
return true;
}
else {
return false;
}
}
int station::showCurrentCar() {
return current_car;
}
bool station::removeFromStation() {
if(current_car != -1) {
current_car = -1;
return true;
}
return false;
}
bool station::addToStack() {
if(current_car == -1 or s.l.size() > 5) {
return false;
}
else {
bool success = s.addToStack(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
}
bool station::removeFromStack() {
if(s.l.size() == 0 or current_car != -1) {
return false;
}
current_car = s.removeFromStack();
return true;
}
int station::showTopOfStack() {
if(s.l.size() == 0) {
return -1;
}
return s.showTopOfStack();
}
int station::showSizeOfStack() {
return s.l.size();
}
bool station::addToQueue() {
if(current_car == -1 or q.l.size() > 5) {
return false;
}
else {
bool success = q.addToQueue(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
}
bool station::removeFromQueue() {
if(q.l.size() == 0 or current_car != -1) {
return false;
}
current_car = q.removeFromQueue();
return true;
}
int station::showTopOfQueue() {
if(q.l.size() == 0) {
return -1;
}
return q.showTopOfQueue();
}
int station::showSizeOfQueue() {
return q.showSizeOfQueue();
}
bool station::addToDequeLeft() {
if(current_car == -1 or d.l.size() > 5) {
return false;
}
else {
bool success = d.addToDequeRight(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
return false;
}
bool station::addToDequeRight() {
if(current_car == -1 or d.l.size() > 5) {
return false;
}
else {
bool success = d.addToDequeLeft(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
}
bool station::removeFromDequeLeft() {
if(d.l.size() == 0 or current_car != -1) {
return false;
}
current_car = d.removeFromDequeLeft();
return true;
}
bool station::removeFromDequeRight() {
if(d.l.size() == 0 or current_car != -1) {
return false;
}
current_car = d.removeFromDequeRight();
return true;
}
int station::showTopOfDequeLeft() {
if(d.l.size() == 0) {
return -1;
}
return d.showTopOfDequeLeft();
}
int station::showTopOfDequeRight() {
if(d.l.size() == 0) {
return -1;
}
return d.showTopOfDequeRight();
}
int station::showSizeOfDeque() {
return d.showSizeOfDeque();
}
bool station::addToIRDequeLeft() {
if(current_car == -1 or ir.l.size() > 5) {
return false;
}
else {
bool success = ir.addToIRDequeLeft(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
return false;
}
bool station::removeFromIRDequeLeft() {
if(ir.l.size() == 0 or current_car != -1) {
return false;
}
current_car = ir.removeFromIRDequeRight();
return true;
}
bool station::removeFromIRDequeRight() {
if(ir.l.size() == 0 or current_car != -1) {
return false;
}
current_car = ir.removeFromIRDequeLeft();
return true;
}
int station::showTopOfIRDequeLeft() {
if(ir.l.size() == 0) {
return -1;
}
return ir.showTopOfIRDequeRight();
}
int station::showTopOfIRDequeRight() {
if(ir.l.size() == 0) {
return -1;
}
return ir.showTopOfIRDequeLeft();
}
int station::showSizeOfIRDeque() {
return ir.l.size();
}
bool station::addToORDequeLeft() {
if(current_car == -1 or ord.l.size() > 5) {
return false;
}
else {
bool success = ord.addToORDequeRight(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
return false;
}
bool station::addToORDequeRight() {
if(current_car == -1 or ord.l.size() > 5) {
return false;
}
else {
bool success = ord.addToORDequeLeft(current_car);
if(success) {
current_car = -1;
return true;
}
return false;
}
}
bool station::removeFromORDequeLeft() {
if(ord.l.size() == 0 or current_car != -1) {
return false;
}
current_car = ord.removeFromORDequeLeft();
return true;
}
int station::showTopOfORDequeLeft(){
if(ord.l.size() == 0) {
return -1;
}
return ord.showTopOfORDequeLeft();
}
int station::showSizeOfORDeque() {
return ord.l.size();
}