Question: Develop and test two classes: a linked list-based stack ADT that implements the provided StackInterface.java a linked list-based queue ADT that implements the provided QueueInterface.java
Develop and test two classes:
a linked list-based stack ADT that implements the provided StackInterface.java
a linked list-based queue ADT that implements the provided QueueInterface.java
The interfaces can be found in the attached Eclipse project file.
The attached Eclipse project file also includes two linked list node classes, one for a singly linked list and one for a doubly linked list. You must use these node classes for your linked lists. Both of your implementations can be based on singly linked list, or both can be based a doubly linked list, or you may use a singly linked list for one and a doubly linked list for the other. Be ready to defend your choice of singly vs. doubly linked list for each implementation.
Please include a toString( ) method in each ADT.
The attached Eclipse project file also includes test/driver programs so that you can focus on the ADT implementations.
Included code below
public interface QueueInterface<E> {
void enqueue(E element); // add an element to the queue - always at the end of the queue
E dequeue(); // remove and return the front of the queue
boolean isEmpty();
boolean isFull();
}
_________________________________________________________________________________________
public interface StackInterface<E> {
void push(E element); // add an element to the stack - always at the "top"
E pop(); // remove and return the top of the stack
E peek(); // return the top of the stack ... without removing
boolean isEmpty();
boolean isFull();
}
_________________________________________________________________________________________
public class DLLNode<E> {
private E info;
private DLLNode<E> next;
private DLLNode<E> prev;
public DLLNode(E info) {
this.info = info;
next = null;
prev = null;
}
public void setInfo(E info) {
this.info = info;
}
public E getInfo() {
return info;
}
public void setNext(DLLNode<E> reference) {
this.next = reference;
}
public DLLNode<E> getNext() {
return next;
}
public void setPrev(DLLNode<E> reference) {
this.prev = reference;
}
public DLLNode<E> getPrev() {
return prev;
}
}
_________________________________________________________________________________________
public class LLNode<E> {
private E info;
private LLNode<E> next;
public LLNode(E info) {
this.info = info;
next = null;
}
public E getInfo() {
return info;
}
public void setInfo(E info) {
this.info = info;
}
public LLNode<E> getNext() {
return next;
}
public void setNext(LLNode<E> next) {
this.next = next;
}
}
_________________________________________________________________________________________
public class QPlay {
public static void main(String[] args) {
LLQueue<Integer> myQ = new LLQueue<Integer>();
for (int i = 0; i < 10; i++) {
if (i % 2 == 1) {
myQ.enqueue(i);
}
}
System.out.println(myQ);
while (!myQ.isEmpty()) {
myQ.dequeue();
}
System.out.println(myQ.isEmpty() ? "It's empty now!" : "How did I get here?");
System.out.println(myQ);
}
}
_________________________________________________________________________________________
public class StackPlay {
public static void main(String[] args) {
LLStack<String> myStack = new LLStack<String>();
myStack.push("Panther");
myStack.push("Imagine");
myStack.pop( );
myStack.push("Black");
myStack.push("Only");
myStack.push("Pink");
myStack.pop( );
myStack.pop( );
myStack.push("Entebbe");
myStack.push("Can");
myStack.push("Raider");
myStack.pop( );
myStack.pop( );
myStack.push("I");
myStack.pop( );
myStack.pop( );
System.out.println(myStack);
System.out.println(myStack.isFull() ? "myStack is full" : "myStack is not full");
System.out.println(myStack.isEmpty() ? "myStack is empty" : "myStack is not empty");
System.out.println("\n");
myStack.pop( );
myStack.pop( );
System.out.println(myStack);
System.out.println(myStack.isEmpty() ? "myStack is empty" : "myStack is not empty");
}
}
Step by Step Solution
3.41 Rating (154 Votes )
There are 3 Steps involved in it
To implement the linked listbased stack and queue as described we will use the provided singly linked list LLNode and doubly linked list DLLNode classes and the interfaces StackInterface and QueueInterface Heres a stepbystep guide and implementation Linked ListBased Stack Choice We will use the singly linked list LLNode for the stack as accessing the top head of the stack is efficient with no need to traverse or modify from the tail Implementation Steps 1 Define the LLStack class Implements StackInterface 2 Use LLNode class ... View full answer
Get step-by-step solutions from verified subject matter experts
