Stacks and Queues Flashcards
1
Q
Is a Stack LIFO or FIFO?
A
LIFO - Last in first out
2
Q
How does a Stack work?
A
- A single pointer is used to point to the top item of the stack, when an item is pushed the pointer is incremented and the new item is inserted at this location.
- When an item is popped, the pointer decrements to point to the new top of the stack
3
Q
Is a Queue LIFO or FIFO?
A
FIFO - First in first out
4
Q
How does a Queue work?
A
- Uses a pair of pointers, one for the front and one for the back of the queue
- If an item is popped the item at the tail pointer is removed
- If an item is being pushed onto the Queue the front pointer increments and the new item is pushed to this location