using namespace std; #include #include "commands_queue.h" static boolean emptyp (queue Q) { return (boolean) (Q.head == NULL); } void init(queue & Q) { Q.head = Q.tail = NULL; } retval enqueue(command * cmd,queue & Q) { node * np = new node; if (np==NULL) return FAIL; np->cmd=cmd; np->next=NULL; if (emptyp(Q)) Q.head=Q.tail=np; else { Q.tail->next=np; Q.tail=np; } return OK; } retval dequeue(command * & cmd,queue & Q) { node * first; if (emptyp(Q)) return FAIL; first = Q.head; cmd = first->cmd; Q.head = Q.head->next; delete first; if (emptyp(Q)) Q.tail = NULL; return OK; } void print(queue Q) { if (!emptyp(Q)) { node * first=Q.head; do { cout << first->cmd->c << " " << first->cmd->i << endl; first = first->next; } while (first != NULL); cout << endl; } }