Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implement the following methods with the given code public class A5Stack implements Stack { private Node head; public A5Stack() { // TODO: implement this }

implement the following methods with the given code 
public class A5Stack implements Stack { private Node head; public A5Stack() { // TODO: implement this } public void push(T v) { // TODO: implement this } public T pop() { // TODO: implement this return null; // so it compiles } public T top() { // TODO: implement this return null; // so it compiles } public void popAll() { // TODO: implement this } public boolean isEmpty() { // TODO: implement this return false; // so it compiles } }
interface Stack { /* * Purpose: Insert an item onto the top of the stack * Parameters: T - the item to insert * Returns: Nothing */ public void push(T v); /* * Purpose: Removes and returns the top item from the stack * Parameters: None * Returns: T - the data value of the element removed * Throws: EmptyStackException if stack is empty */ public T pop(); /* * Purpose: Accesses the top item on the stack * Parameters: None * Returns: T - the data value of the top element * Throws: EmptyStackException if stack is empty */ public T top(); /* * Purpose: Determines whether the stack is empty * Parameters: None * Returns: boolean - true if the stack is empty, false otherwise */ public boolean isEmpty(); /* * Purpose: Removes all elements from the stack * Parameters: None * Returns: Nothing */ public void popAll(); }
public class Node{ private T data; protected Node next; public Node (T value) { this.data = value; this.next = null; } /* Parameters: nothing * Purpose: get the data value of this Node * Returns: int - the value */ public T getData() { return data; } /* Parameters: nothing * Purpose: get the next of this Node * Returns: (Node) the next */ public Node getNext() { return next; } /* Parameters: Node next * Purpose: set the next of this Node to next * Returns: nothing */ public void setNext(Node next) { this.next = next; } }

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago