Queue uses FIFO(first-in first-out) ordering.
class Queue { Node *first, *last; public: void enqueue(Node *item) { if (first == NULL) { last = new Node(item); first = last; } else { last->next = new Node(item); last = last->next; } } int dequeue(Node *n) { if (first != 0) { Node *item = first; first = first->next; int val = item->value; delete item; return val; } } };