Computer Science – 10.4 Introduction to Abstract Data Types (ADT) | e-Consult
10.4 Introduction to Abstract Data Types (ADT) (1 questions)
Queue Implementation using Arrays:
A queue follows the FIFO (First-In, First-Out) principle. An array can be used to implement a queue, but it requires careful management of indices to maintain the queue's order. A common approach is to use two pointers: a 'front' pointer indicating the head of the queue and a 'rear' pointer indicating the tail. New elements are added to the rear, and elements are removed from the front. When the queue is full, the front pointer needs to be advanced, potentially overwriting the oldest element. This can lead to a fixed capacity limitation.
Operations:
- enqueue(element): Add an element to the rear (rear pointer incremented).
- dequeue(): Remove and return the element at the front (front pointer incremented).
- isEmpty(): Check if the queue is empty (front == rear).
- isFull(): Check if the queue is full (front + 1 == rear).
Advantages: Simple to implement, efficient if the array size is known in advance.
Disadvantages: Fixed size, potential for wasted space if the queue is rarely full, can be inefficient if frequent resizing is needed.