Write Java interfaces for the following ADTs For each part j

Write Java interfaces for the following ADTs. (For each part, just write an interface that specifies methods do not implement these methods.) Stack Queue Deque Write a Java implementation for the following problem. You can make use of whichever of the ADTs Stack, Queue, and Deque that you need. Assume that these ADTs are already implemented, compiled and available in files Stack.class Queue.class, Deque.class. Input is read from the terminal (System.in). All input Strings are read and stored. The input Strings BEGIN, END, and PRINT have special meanings. Whenever a String that matches PRINT is read, all stored strings that appear after the last stored BEGIN string are printed (in the same order that they were entered). These printed strings together with their enclosing BEGIN and PRINT strings are removed from storage. If there is no stored BEGIN string an Exception should be thrown. When the string END is read, the program terminates. For example, if the input is: BEGIN is This PRINT BEGIN easy. PRINT END the output would be: is This easy. Or if the input is: BEGIN is This BEGIN easy. PRINT ignore END the output would be easy. is This

Solution

Problem 13:

(i) Stack

Class Stack

java.lang.object<E>

java.utill.abstractcollection<E>

java.utill.abstractList<E>

java.utill.vector<E>

All Implemented interfaces:

Serializable, clonable, iterable, collection, list<E>, Randomaccess

All implemented interfaces:

java.lang.iterable , java.util.collection   

(ii) Queue:

A Queue is collection for holding elementsprior to proceeding. It provides additional insertion, removal, and inspection operartions.

public interface Queue<E> extends collection<E> {

E element();

boolean offer(E e);

E peek();

E poll();

E remove();

}

(iii) Dequeue:

   The dequeue interface is a richer richer abstract than both Stack and Queue because it implements both Stack and Queue at the same time. This interface defines methods to access the elements at both ends of the Dequeue instance Methods provided are insert,remove and examine the elements.

Predefined classes like ArrayDeque and LinkedList implement the Deque iterface.

( Deque Methods)

Type of operation:

Insert :   FirstElement LastElement

addFirst(e) addLast(e)

offerFirst(e) offerlast(e)

Remove: removeFirst() removeLast()

pollFirst() pollLast()

Examine: getFirst() getLast()

peekFirst() peekLast()

 Write Java interfaces for the following ADTs. (For each part, just write an interface that specifies methods do not implement these methods.) Stack Queue Deque
 Write Java interfaces for the following ADTs. (For each part, just write an interface that specifies methods do not implement these methods.) Stack Queue Deque

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site