Queue Flashcards
A queue is structured in a…
FIFO(First in first out)
What does the dequeue method do?
Removes data from the front of the queue
What does the enqueue method do?
Adds a data item to the rear end of the queue
What does first() operation do?
Returns the data item at the front of the queue without removing it
What does the isEmpty method do?
Determines weather the queue is empty
What does the size method do?
Returns a string representation of the queue
What does the toString method do?
It returns a string representation of the queue
What 3 things is needed to implement a queue?
- A data structure to hold the data items
- A way to indicate the front of the queue
- A way to indicate the rear of the queue
How do you implement a linked list implementation of a queue?
We need 2 pointers, front, rear, and one variable called count to store the number of data items
What 2 cases are mostly considered when dealing with a linked list? Enqueue operation
- The queue is empty
- The queue is not empty
What 3 cases are considered for the Dequeue operation in a linked list?
- The queue is empty
- the queue has one data item
- The queue has more than 1 data item
How would a queue be implemented using an array?
Using 2 variables: front = 0 and count = number of data items
2 cases to consider using an array and the enqueue operation?
- The array is full
- The array is not full
What 2 cases to consider for the dequeue Operation and using an array?
- The queue is empty
- The queue is not empty
What do we need to keep track of when implementing a queue as a circular array?
We need to keep track of the front data item and the rear data item