Chapter 3 Queue Data Structure Using Array (2)
Chapter 3 Queue Data Structure Using Array (2)
Data Structures
• A queue is an ordered list (According to the arrival time) where insertions are made at
one end (the rear) and deletions are made at the other end (the front).
• Rear (tail): the last entry in the queue. That is the most recent entry.
1. Objects:
A finite ordered list with zero or more elements.
front (head) indicator indicates the first (oldest) entry in the queue.
rear (tail) indicator indicates the last (most recent) entry in the queue.
2. Methods (operations) implemented using Array:
isEmpty(): Check if the queue is empty.
isFull(): Check if the queue is full.
enqueue(): Add (store) an item to the queue.
dequeue(): Remove (access) an item from the queue.
length(): Retrieve the number of elements in the queue.
first(): Returns the element at the front of the queue but does not remove
it.
Faculty of Information Technology - Computer Science Department 7
How to Hold Queue Elements?
•We have two design options for how to hold the queue elements in the array:
Fixed front design: The front indicator of the queue is fixed while the
rare
indicator changes.
Floating front design: Both front and rear indicators change and the array
is treated as a circular structure.
11
Faculty of Information Technology - Computer Science Department
Exercises
𝑄𝑢𝑒𝑢𝑒𝐴𝑟𝑟
2. In the main class (𝑄𝑢𝑒𝑢𝑒𝐴𝑟𝑟𝐷𝑒𝑚𝑜), create a queue object using
12
Faculty of Information Technology - Computer Science Department