Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description : Your objective is to implement a stack and a queue using the list implementation you did in assignment #3. You must use the

Description: Your objective is to implement a stack and a queue using the list implementation you did in assignment #3. You must use the linked list implementation of a list. You are to use your list operations to accomplish the operations of a stack and queue. Getting started: Grab your ListAsLinkedList class and your Node class from assignment #3 In the List.java file given to you, where it says "public class List", put your ListAsLinkedList class's fields and methods. To be clear, this creates a new class called List (that does NOT implement IList) that is the exact same as your ListAsLinkedList class. DON'T FORGET to rename the constructor to "List". Where it says "class Node", put your Node class's fields and methods. You will not need the IList interface nor the ListAsArray class, so do NOT include them. The Stack.java and Queue.java files given to you are where you will implement your stack and queue. They have been "stubbed out" meaning method "stubs", or blank methods, have been created for you. These need to be given an implementation that will carry out the operations. Running the code: The Main.java file contains the entry point, so compiling and running that class will run the application. The undo command in the game relies on a correct stack implementation and the replay command relies on a correct queue implementation. Testing these two commands will test your stack and queue implementations and ensure they are functioning correctly. ADD GENERICS!!

QUEUE CODE

/** Queue abstract data type */ public class Queue { /** List objects to hold our queue items. Use List operations to implement the methods below */ private List list; public Queue() { // instantiate list here } public void enqueue(char value) { } public char dequeue() { } public char front() { } public boolean isEmpty() { } }

STACK CODE

/** Stack abstract data type */ public class Stack { /** List objects to hold our stack items. Use List operations to implement the methods below */ private List list; public Stack() { // instantiate list here } public void push(char value) { } public char pop() {

NECCESARY CODE FROM ASSIGNMENT 3 
/** Linked List implementation of our List abstract data type */ public class List { // put all fields from ListAsLinkedList class here class ListAsLinkedList implements IList { /** * references to head and tail nodes of this list */ private Node head, tail; /** * count of current number of elements in this list */ private int count; //constructor initializing empty list public ListAsLinkedList() { head=null; tail=null; count=0; } @Override public void append(char value) { //creating a new node with given value Node newNode=new Node(value); //if head is null, adding as both head and tail if(head==null){ head=newNode; tail=newNode; }else{ //otherwise appending to tail and updating tail tail.next=newNode; tail=newNode; } //updating count count++; } @Override public void prepend(char value) { //creating a new node with given value Node newNode=new Node(value); //if head is null, adding as both head and tail if(head==null){ head=newNode; tail=newNode; }else{ //otherwise adding before head and updating head newNode.next=head; head=newNode; } //updating count count++; } @Override public void deleteAt(int position) { //verifying position if(position>=0 && position=count){ throw new IndexOutOfBoundsException("Invalid position: " + position); } Node temp=head; //advancing temp position number of times for(int i=0;i
 } public char peek() { } public boolean isEmpty() { } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+3. If its a stock transaction, what is the exchange ratio?

Answered: 1 week ago

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago