Imagine that we have developed a Queue to hold double values

Imagine that we have developed a Queue to hold double values with the following API Queue() void enqueue(double d) double dequeue() double peek() boolean isEmpty() For the following questions, use only the existing API unless otherwise indicated in the question. Write a Java code fragment to create an empty queue. Write a Java code fragment to create a queue containing the following values: Write a Java code fragment to create a queue containing the following values:

Solution

1)

class arrayQueue{

protected int Queue[] ;

protected int front, rear, size, len;

/* Constructor */

public arrayQueue(int n)

{

size = n;

len = 0;

Queue = new int[size];

front = -1;

rear = -1;

}

}

2)

class arrayQueue{
protected int Queue[] ;
protected int front, rear, size, len;
/* Constructor */
public arrayQueue(int n) {
size = n;
len = 0;
Queue = new int[size];
front = -1;
rear = -1;
}

/* Function to insert an element to the queue */
public void insert(int i) {
if (rear == -1) {
front = 0;
rear = 0;
Queue[rear] = i;
}
else if (rear + 1 >= size)
throw new IndexOutOfBoundsException(\"Overflow Exception\");
else if ( rear + 1 < size)
Queue[++rear] = i;
len++ ;
}   

}

public class QueueImplement{
public static void main(String[] args){
/* creating object of class arrayQueue */
arrayQueue q = new arrayQueue(n);

  q.insert(0.3 );

  q.insert(0.5);

}

}

3)

class arrayQueue{
protected int Queue[] ;
protected int front, rear, size, len;
/* Constructor */
public arrayQueue(int n) {
size = n;
len = 0;
Queue = new int[size];
front = -1;
rear = -1;
}

/* Function to insert an element to the queue */
public void insert(int i) {
if (rear == -1) {
front = 0;
rear = 0;
Queue[rear] = i;
}
else if (rear + 1 >= size)
throw new IndexOutOfBoundsException(\"Overflow Exception\");
else if ( rear + 1 < size)
Queue[++rear] = i;
len++ ;
}   

}

public class QueueImplement{
public static void main(String[] args){
/* creating object of class arrayQueue */
arrayQueue q = new arrayQueue(n);

  q.insert(8.72);

  q.insert(14.2);

q.insert(-8.13);

q.insert(22.41 );

}

}

 Imagine that we have developed a Queue to hold double values with the following API Queue() void enqueue(double d) double dequeue() double peek() boolean isEmp
 Imagine that we have developed a Queue to hold double values with the following API Queue() void enqueue(double d) double dequeue() double peek() boolean isEmp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site