Stacks and Queues Flashcards
What is a queue?
A First In First Out (FIFO) linear data structure that maintain the order of the data
What is at the front an back of queues?
Front pointer and a back pointer / head/tails pointer
What should be considered before enqueueing or dequeuing an item?
If the queue is full (queue overflow) or if the queue is empty (queue underflow)
Why is using arrays to implement a queue a problem?
Both the back and front pointers are moving in the same direction as items are added and removed - array will quickly run out of space
How to we solve the problem caused by implementing a queue using an array?
Cycle the back pointer to the front of the array when it reaches the end
An example of a queue
Transferring data between processors and printers - process scheduling
What is a stack?
A Last In First Out (LIFO) data structure - the last item to be pushed onto the stack must be the first item to be popped off
What is at the top of a stack?
A stack pointer
What should be considered before pushing or popping an item?
If the stack is full (stack overflow) or if the stack is empty (stack underflow)
An example of a stack
Keeping track of user inputs for undo operations