Professional Documents
Culture Documents
and pop at the head of the list New nodes should be inserted at the front of the list, so that they become the top of the stack Nodes are removed from the front (top) of the list
top
top 1 6
top
7 1 6
top
7 1 6
Simple implementation
The size of the queue must be determined when a stack object is declared Space is wasted if we use less elements We cannot "enqueue" more elements than the array can hold
Allocate memory for each new element dynamically Link the queue elements together
Use two pointers, qFront and qRear, to mark the front and rear of the queue
10
11
qRear = NULL
newNode
12
13
Node
qRear
14
15