Question: I need help for this Java program. There are starter code and requirements. package circularqueue; import static java.lang.Math.E; /** * * */ public class CircularQueue

I need help for this Java program. There are starter code and requirements.

I need help for this Java program. There are starter code andrequirements. package circularqueue; import static java.lang.Math.E; /** * * */ public class

CircularQueue implements CircularQueueInterface { private Node rear; private int length; /** *

package circularqueue;

import static java.lang.Math.E;

/**

*

*

*/

public class CircularQueue implements CircularQueueInterface {

private Node rear;

private int length;

/**

* this inner class is used to create nodes of a singly-linked queue

*/

private class Node

{

public E data;

public Node next;

}

/**

* Creates an empty singly-linked queue

*/

public CircularQueue()

{

// Implement this constructor

}

public int size()

{

// Implement this method

}

/**

* Determines whether the queue is empty.

* @return true if the queue is empty;

* otherwise, false

*/

public boolean isEmpty()

{

// Implement this method

}

/**

* Inserts an item at the back of the queue.

* @param data the value to be inserted.

*/

public void enqueue(E data)

{

// Implement this method

}

/**

* Accesses the item at the front of a non-empty queue

* @return item at the front of the queue.

* @throws Exception when this queue is empty

*/

public E front() throws Exception

{

// Implement this method

}

/**

* Deletes an item from the front of the queue.

* @return item at the front of the queue.

* @throws Exception when this queue is empty

*/

public E dequeue() throws Exception

{

// Implement this method

}

/**

* Moves the node at the front of the queue to the back.

*/

public void rotateClockwise()

{

// Implement this method

}

/**

* Moves the node at the back of the queue to the front.

*/

public void rotateCounterclockwise()

{

// Implement this method

}

/**

* Returns a string [en-1, ..., e2, e1, e0] representing this queue,

* where e0 is the data item in the head bode and en-1 is the data item

* in the rear node. It returns [] if this queue is empty.

*/

public String toString()

{

// Implement this method

}

}

package circularqueue;

/** * * */ public interface CircularQueueInterface { int size(); boolean isEmpty(); void enqueue(E data); E front() throws Exception; E dequeue() throws Exception; }

package circularqueue;

/** * * */ public class CircularQueueDemo { public static void main(String []args) { try { CircularQueue chars = new CircularQueue(); chars.enqueue('S'); System.out.printf("%c inserted in the queue. ",'S'); chars.enqueue('T'); System.out.printf("%c inserted in the queue. ",'T'); chars.enqueue('R'); System.out.printf("%c inserted in the queue. ",'R'); chars.enqueue('E'); System.out.printf("%c inserted in the queue. ",'E'); chars.enqueue('S'); System.out.printf("%c inserted in the queue. ",'S'); chars.enqueue('S'); System.out.printf("%c inserted in the queue. ",'S'); chars.enqueue('E'); System.out.printf("%c inserted in the queue. ",'E'); chars.enqueue('D'); System.out.printf("%c inserted in the queue. ",'D'); System.out.println(); System.out.println("Queue = " + chars); System.out.println(); if (!chars.isEmpty()) System.out.println("The queue is not empty."); else System.out.println("The queue is empty."); System.out.println(); chars.rotateClockwise(); System.out.println("After rotating clockwise, queue = " + chars); chars.rotateCounterclockwise(); System.out.println("After rotating counterclockwise, queue = " + chars); System.out.println(); while (!chars.isEmpty()) { System.out.printf("%c is at the front of the queue. ", chars.front()); System.out.printf("%c has been removed from the front. ", chars.dequeue()); System.out.println("Queue = " + chars); System.out.println(); } if (!chars.isEmpty()) System.out.println("The queue is not empty."); else System.out.println("The queue is empty."); System.out.println(); System.out.println("Calling nums.front()"); System.out.printf("%c is at the front of the queue. ", chars.front()); } catch(Exception e) { System.out.println(e); } } }

eneric Circular Queue with Singly-Linked Nodes and One External Pointer the rear of the queue and queue is a FIFO (first in first out) abstract data type (ADT) in which nodes are a d removed at the head of the queue. There are several ways of eing a queue. In lecture class we presented a generic straight-line queue gnked nodes (each node has one pointer, named next, that points to the nex that was added to the queue) and two external pointers, named head and rear, that point to the head node and rear node of the queue. In today's lab you will implement a circular variant of the generic straight-line queue presented in class. In this circular variant, each node has one pointer, named next points to the next node that was added to the queue (as in the one we did in class), but the rear node's pointer, instead of being null, points to the head node, and the queue has on one external pointer, named rear, t the head node). Thus in this variant, the head node can only be accessed using the rear node's pointer. This circular queue is illustrated on the following page: hat points to the rear node (there is no external pointer to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!