Question: Consider the following partial implementation of a generic LIFO MyStack data structure that contains subtypes of Comparable and supports the operations isEmpty ( ) ,
Consider the following partial implementation of a generic LIFO MyStack
data structure that contains subtypes of Comparable and supports the operations
isEmpty push pop and returnMin Note that the latter merely returns the
minimum element stored in the MyStack but doesnt delete it We will assume that
MyStack always contains distinct elements.
The MyStack is expandable in the sense that the client code may push an arbitrary
number of elements to it Except for deleteMin all operations must have worstcase
running time O We will assume compareTo has worstcase running time O
The following is a partial implementation of MyStack, with method stubs:
public class MyStack
private class Node
public Node next;
public T obj;
public Node Node next, T obj
this.next next;
this.obj obj;
public boolean isEmpty Must be O
return false;
public void pushT obj Must be O
public T pop Must be O
return null;
public T returnMin Must be O
return null;
public void deleteMin
DO NOT IMPLEMENT THIS METHOD!
a Provide a valid Java implementation of MyStack that achieves the run
ning time requirements listed above. However, DO NOT implement deleteMin
and DO NOT add code that explicitly checks for or filters out duplicate objects we
will assume the client code never attempts to add a duplicate element
You must use the given starter code. Dont use any builtin classes beyond what is
referenced in the starter code. All MyStack methods must be implementations of
deterministic, sequential, and comparisonbased algorithms. The latter requirement
means that the methods must only call compareTo on the contained elements.
Full credit will be given to code that is selfdocumenting and formatted in a con
sistent manner.
There is no Put your answer here box for this part. Please put your code in
a corresponding MyStack.JAVA file and include it with your submission.
b Assume all MyStack methods, including deleteMin are correct im
plementations of deterministic, sequential, and comparisonbased algorithms. Is it
possible to implement all of them, including deleteMin to have worstcase run
ning time O Justify your answer. DO NOT implement or discuss any particular
potential implementation of deleteMin
Hint: Full credit will not be given to solutions that discuss details of a particular
implementation of deleteMin
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
