Question: 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

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!