#include #include "scolor.hpp" using namespace std; struct Node { string data; Node *next; }; class Stack { Node *start = 0; public: void push(string new_word){ Node *nnode = new Node; nnode->data = new_word; nnode->next = start; start = nnode; } string pop(){ if(start){ Node *backup = start; string retval = backup->data; start = start->next; delete backup; return retval; } return ""; } bool empty(){ return start == 0; } }; class Queue { Node *start = 0; Node *end = 0; public: void enqueue(string new_word){ Node *nnode = new Node; nnode->data = new_word; nnode->next = 0; if(end){ end->next = nnode; end = end->next; } else { end = nnode; start = nnode; } } string dequeue(){ if(start){ if(end == start) end = 0; Node *backup = start; string retval = backup->data; start = start->next; delete backup; return retval; } return ""; } bool empty(){ return start == 0; } }; int main(){ Stack tasks; tasks.push("Finish teaching class"); tasks.push("Ride home and get kids and leave again"); tasks.push("Come and teach 430 tomorrow"); while(!tasks.empty()) cout << "I need to: " << tasks.pop() << endl; Queue more_tasks; more_tasks.enqueue("Clean birdcage"); more_tasks.enqueue("Change oil"); more_tasks.enqueue("Chase goat out of wherever it shouldn't be"); more_tasks.enqueue("Go skiing"); while(!more_tasks.empty()) cout << "Next task: " << more_tasks.dequeue() << endl; return 0; }