Question 23
Question 23
Queue is an entity which can hold a maximum of 100 integers. The queue
enables the user to add integers from the rear and remove integers from the
front.
Define a class Queue with following details:
Class name: Queue
Data Members / instance variables:
Que[]: Array to hold the integer elements.
size : Stores the size of the array.
front: To point the index of the front.
rear: To point the index of the rear.
Member functions/methods:
Queue (int mm) : Constructor to initialize the data. size = mm, front = 0, rear =
0.
void addele (int v) : to add integers from the rear if possible else display the
message 'overflow".
int delele () : returns elements from front if possible, otherwise display the
message "Underflow" and return -9999.
void display (): displays the array elements.
Specify the class Queue giving details of ONLY the functions void addele (int)
and int delele ().
Assume that the other functions have been defined.
The main function and algorithm need not be written.
Program
class Queue
{
int[] queue;
int size;
int front;
int rear;
Variable Description
Variable Data
Description
Name Type
queue Array to store the elements of the queue int[]
size Maximum capacity of the queue int
front Index of the front element int
rear Index of the rear element int
value Temporary variable to store values during enqueue int
and dequeue operations
i Loop counter for iterating through the queue int
Algorithm
1. Start.
2. Define the Queue class with the following instance variables
3. Implement the constructor to initialize the queue array and set front
and rear to -1.
4. Implement the enqueue method
5. Implement the dequeue method
6. Implement the isFull method
7. Implement the isEmpty method
8. Implement the display method.
9. Stop.
Output