Question
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 the 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:
Queue (int mm):constructor to initialize the data size = mm, front = 0, rear = 0
void addele(int v ):to add integer from the rear if possible else display the message “Overflow”
int delele( ):returns elements from front if present, otherwise displays 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.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
public class Queue
{
void addele(int v)
{
if(r< size)
{
Que[r]=v;
r=r+1;
}
else
{
System.out.println(" Overflow");
}
}
int delele()
{
if(f==r)
{
System.out.println("UnderFlow");
return -9999;
}
else
{
return Que[f++];
}
}
}