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

Your objective is to implement a stack and a queue using the list implementation you did in program #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

.

Here's the program 3 list:

public class List { // put all fields from ListAsLinkedList class here //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) { //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{ //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{ newNode.next=head; head=newNode; } //updating count count++; } @Override public void deleteAt(int position) { if(position>=0 && position=count){ throw new IndexOutOfBoundsException("Invalid position: " + position); } Node temp=head; for(int i=0;i

HERE IS THE QUEUE.JAVA TEMPLATE:

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() { } }

Here is the stack template:

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() { } public char peek() { } public boolean isEmpty() { } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!