Question: An UltraStack is an extended stack that supports eight main operations: the standard Stack operations push ( x ) and pop ( ) and the
An UltraStack is an extended stack that supports eight main operations: the standard Stack
operations pushx and pop and the following nonstandard operations:
geti: returns the i th element from the bottom on the Stack.
seti x: sets the value of the i th element from the bottom on the Stack to x and
returns the element that was previously stored at the same position.
doubleTop: reads the top element x from the Stack and adds a new element x to the top
of the Stack.
swapTop: swaps the top two elements of the Stack.
max: returns the maximum value stored on the Stack.
ksumk: returns the sum of the top k elements on the Stack.
The zip file gives an implementation of UltraSlow, which correctly implements these operations so
that pushx pop geti doubleTop swapTop and seti x each run in time,
but max and ksumk run in time. The provided implementation of the UltraFast is just a
copy of UltraSlow implementation.
You must complete the implementation of UltraFast by correctly coding all eight operations and
optimizing their efficiency. For UltraFast, the running time for geti and max must be and
for pushx pop seti x doubleTop swapTop and ksumk running time must not
exceed
You may assume that the Stack elements will be in the range
As part of your implementation, you may use any of the classes in the Java Collections Framework and
you may use any of the source code provided with the Java version of the ODS textbook.
Remember to implement both the size and iterator methods. The iterator method
should return an Iterator that iterates over the values in order, starting from the bottom
and ending at the top of the Stack. Your iterator must support the following two methods:
next that returns the next element in the iteration.
hasNext that returns true if this list iterator has more elements when traversing the list in
the forward direction. In other words, returns true if next would return an element rather
than throwing an exception.
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
