Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implementing the size() and toString() method public interface MyStackInterface { /** Gets the current number of data in this stack. @return the integer number of

Implementing the size() and toString() method

public interface MyStackInterface {

/** Gets the current number of data in this stack. @return the integer number of entries currently in the stack*/ public int size();

/** Adds a new data to the top of this stack. @param aData an object to be added to the stack */ public void push(T aData); /** Removes and returns this stack's top data. @return either the object at the top of the stack or, if the stack is empty before the operation, null */ public T pop(); /** Retrieves this stack's top data. @return either the data at the top of the stack or null if the stack is empty */ public T peek(); /** Detects whether this stack is empty. @return true if the stack is empty */ public boolean empty(); /** Removes all data from this stack */ public void clear(); } // end MyStackInterface

--------------------------------------------------------------------------------------------

public class MyLinkedStack implements MyStackInterface

{

// Data fields

private StackNode top; // references the first node in the chain

private int count; // number of data in this stack

public MyLinkedStack()

{

// add stataments

} // end default constructor

public void push(T newData)

{

// add stataments

} // end push

public T peek()

{

// add stataments

return null;

} // end peek

public T pop()

{

// add stataments

return null;

} // end pop

public int size()

{

// add stataments

return 0;

} // end size

public boolean empty()

{

// add stataments

return false;

} // end empty

public void clear()

{

// add stataments

} // end clear

public String toString()

{

// add stataments

// note: data class in stack must implement toString() method

// return a list of data in Stack, separate them with ','

return null;

}

}

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

Students also viewed these Databases questions

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago

Question

b. Does senior management trust the team?

Answered: 1 week ago

Question

c. How is trust demonstrated?

Answered: 1 week ago