Write Java interfaces for the following ADTs For each part j
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()


