Forum Stats

  • 3,728,152 Users
  • 2,245,559 Discussions
  • 7,853,357 Comments

Discussions

Please help How to implement Queue in java ?

Implement the array-based Queue in Java assuming the interface is already given in Queue.Java Training. Write a main method to have a Queue with the following operations :

1. enqueue(5); 2. enqueue(3); 3. dequeue();

**Queue.java:

public interface Queue {

/**

* Returns the number of elements in the queue.

* @return number of elements in the queue.

*/

public int size();

/**

* Returns whether the queue is empty.

* @return true if the queue is empty, false otherwise.

*/

public boolean isEmpty();

/**

* Inspects the element at the front of the queue.

* @return element at the front of the queue.

* @exception EmptyQueueException if the queue is empty.

*/

public Object front() throws Exception;

/**

* Inserts an element at the rear of the queue.

* @param element new element to be inserted.

*/

public void enqueue (Object element)throws Exception;

/**

* Removes the element at the front of the queue.

* @return element removed.

* @exception EmptyQueueException if the queue is empty.

*/

public Object dequeue() throws Exception;

}

Any Help?

Implement the array-based Queue in Java assuming the interface is already given in Queue.java. Write a main method to have a Queue with the following operations :
1. enqueue(5); 2. enqueue(3); 3. dequeue();


**Queue.java:

public interface Queue {
/**
* Returns the number of elements in the queue.
* @return number of elements in the queue.
*/
public int size();
/**
* Returns whether the queue is empty.
* @return true if the queue is empty, false otherwise.
*/
public boolean isEmpty();
/**
* Inspects the element at the front of the queue.
* @return element at the front of the queue.
* @exception EmptyQueueException if the queue is empty.
*/
public Object front() throws Exception;
/**
* Inserts an element at the rear of the queue.
* @param element new element to be inserted.
*/
public void enqueue (Object element)throws Exception;
/**
* Removes the element at the front of the queue.
* @return element removed.
* @exception EmptyQueueException if the queue is empty.
*/
public Object dequeue() throws Exception;
}

Tagged:
Sign In or Register to comment.