Download: The Queue
The Queue In Python | Download: The Queue
The Queue is a First In, First Out (FIFO) data structure. This is because the first item you put into the queue will be the first item you will take out. This is useful for when you want to go through data in time order.
- New elements may only be added to the end of a queue. This is called ‘enQueue‘
- Elements may only be retrieved from the front of a queue. This is called deQueue’
Operations On a Queue:
- enQueue(item) – Adds a new item to the end of the queue
- deQueue() – Removes the front item of the queue and returns it
- isEmpty() – Checks if the queue is empty
- isFull() – Checks if the queue is full
Visualising the Queue:
We will now enQueue “B”, “C” & “D”
We will now deQueue
- Data is accessed by two memory locations. The front and the end of the queue.
- It can be used for tasks for when the Stack is not a suitable data structure.
- It makes good use of memory space as there are no gaps.
- It makes good use of processer time as adding or deleting date is just a single operation.
- It is an inflexible data structure.
- The locations of the front and end of the Queue are always changing.
How data is stored in the Queue:
The computer uses pointers to store the start and the end of the queue. This is called the head and the tail.
All the data items stay in the same place. It is only the pointers that move.
Here are some values stored within a Queue data structure:
We will deQueue
The position where the value “B” is located, is now the start of the queue and “G” is the end of the queue.
179 total views, 1 views today