Lab Sheet 5- Queue Operations
Lab Sheet 5- Queue Operations
Lab Objective:
To understand and implement a queue data structure using Java. The aim is to perform
basic queue operations such as Enqueue, Dequeue, Display, and to check whether the queue
is empty or full.
LO1: Construct a queue using an array and implement functions to perform enqueue and
dequeue operations efficiently.
LO2: Apply robust error handling to manage queue overflow and underflow, ensuring the
queue operates reliably under various conditions
Theory:
Queue:
A queue is a linear data structure that follows the First In First Out (FIFO) principle. This
means that the element that is added first is removed first.
Operations in Queue:
1. Enqueue: Add an element to the rear of the queue.
2. Dequeue: Remove and return the element from the front of the queue.
3. isEmpty: Check if the queue is empty.
4. isFull: Check if the queue is full.
5. Display: Display the elements in the queue.
Procedure:
Code Implementation:
Queue Class:
class Queue {
int queue[];
int rear;
int front;
int size;
QueueOperations Class:
import java.util.Scanner;
Sample Input/Output:
Output:
Elements:
10 20
Output:
Deleted Element is: 10
Elements:
20
Output:
is Full: false
Post-Lab Questions:
1. What is the difference between a linear queue and a circular queue?
-2. How does the program handle queue overflow and underflow situations?
3. What happens if the dequeue operation is performed on an empty queue?
4. Modify the program to handle dynamic resizing of the queue.