Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

fill the java code in the answer to complete the method For the question below, assume the following implementation of LinkedStack: 2 1 public class

image text in transcribed

image text in transcribed

image text in transcribed

fill the java code in the answer to complete the method

image text in transcribed

For the question below, assume the following implementation of LinkedStack: 2 1 public class LinkedStack implements StackInterface { private Node topNode; private int numberofEntries; public LinkedStack() { this.topNode = null; numberofEntries = 0; }// end default constructor 8 9 10 11 12 @Override public void push(T newEntry) { topNode = new Node(newEntry, topNode); numberofEntries++; 13 14 15 16 17 18 19 20 21 Coverride public peek() { if (isEmpty()) { throw new EmptyStackexception(); } else { return (T)topNode.getData(); } } // end peek 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 @Override public T pop() { T top = peek(); topNode = topNode.getNext(); numberofEntries--; return top; @Override public boolean isEmpty() { return topNode == null; } 39 40 41 @Override public void clear() { topNode = null; } // end LinkedStack public class Node { private E data; // Entry in bag private Node next; // Link to next node public Node (E dataPortion) { this(dataPortion, null); } // end constructor public Node (E dataPortion, Node nextNode) { data = dataPortion; next = nextNode; } // end constructor public e getData() { if (data != null) { return data; } return null; public Node getNext() { return next; } public void setNext (Node newNext) { next = newNext; } } // end Node Below, you'll see the start of a method to find the bottom item in a stack. So if you had the following code: LinkedStack lstack = new LinkedStack(); Istack.push(5); Istack.push(10); 4 Istack.push(15); running Istack.getBaseOfStack() would return 5. Add in the code to finish this method. Your Answer: @suppressWarnings("unchecked") 2 public T getBaseOfStack() { Node currentNode; 3 4 5 6 7 return currentNode.getData()

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago