#include #include #include "wordlist.h" #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(){ Queue dictionary; ifstream d_file; d_file.open("/usr/share/dict/american-english"); string next_word; while(d_file >> next_word) dictionary.enqueue(next_word); d_file.close(); cout << "Dictionary is loaded\n"; for(int i = 0; i < 10; i++) cout << "Word " << i << ": " << dictionary.dequeue() << endl; return 0; }