3.1 stack and queue Flashcards
Stack abstract data type
push(e) – Insert element e at the top of the stack
* pop() – Remove the top element from the stack; an
error occurs if the stack is empty
* top() – Return a reference to the top element on the
stack, without removing it; an error occurs if the
stack is empty
* size() – Return the number of elements in the stack
* empty() – Return true if the stack is empty and false
otherwise
LIFO (last-in first-out)
stack
Queues
FIFO (First in First out)
Queue Abstract data type
enqueue(e): Insert element e at the rear of the queue
* dequeue(): Remove element at the front of the
queue; an error occurs if the queue is empty
* front(): Return, but do not remove, a reference to the
front element in the queue; an error occurs if the
queue is empty
* size(): Return the number of elements in the queue
* empty(): Return true if the queue is empty and false
otherwise
STL queue
size(): Return the number of elements in the queue
* empty(): Return true if the queue is empty and false
otherwise
* push(e): Enqueue e at the rear of the queue
* pop(): Dequeue the element at the front of the
queue
* front(): Return a reference to the element of the
queue’s front
* back(): Return a reference to the element at the
queue’s rear