Page 621 - Computer science 868 Class 12
P. 621
Program 20 Queue
Design a class Queue to implement Queue concept using an array, given the following class
description:
Data Members
int q[] : An array to implement queue
int front : Stores the front position of the array
int rear : Stores the rear position of the array
int size : Stores the size of the queue
Member Functions
Queue(int) : Parameterised constructor to input array size
void enqueue(int) : To enter an element in the queue
void dequeue() : To remove an element from the queue
void display() : To display the queue
1 import java.util.*;
2 class Queue
3 {
4 int q[];
5 intfront,rear,size;
6 Queue(int s)
7 {
8 front = rear = 0;
9 size = s;
10 q = new int[size];
11 }
12 void enqueue(int x)
13 {
14 if(rear==size-1)
15 {
16 System.out.println("ERROR: Queue Overflow");
17 }
18 else
19 {
20 q[rear++]=x;
21 }
22 }
23 void delqueue()
24 {
619
Internal Assessment 619

