Question: below is the code for UltraStack.java: package comp 2 4 0 2 a 4 ; import java.util.Iterator; public interface UltraStack extends Iterable { public void
below is the code for UltraStack.java: package compa;
import java.util.Iterator;
public interface UltraStack extends Iterable
public void pushint x;
public Integer pop;
public void doubleTop;
public void swapTop;
public Integer getint i;
public Integer setint i int x;
public Integer max;
public long ksumint k;
public int size;
public Iterator iterator;
below is the code for UltraSlow.java: package compa;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
public class UltraSlow implements UltraStack
List ds;
public UltraSlow
ds new ArrayList;
public void pushint x
dsaddx;
public Integer pop
ifdssize
return null;
return dsremovedssize;
public Integer getint i
ifi i dssize
return null;
return dsgeti;
public Integer setint i int x
ifi i dssize
return null;
return dsseti x;
public void doubleTop
if size
dsadddsgetdssize;
public void swapTop
if size
Integer temp dsgetdssize;
dssetdssize dsgetdssize;
dssetdssize temp;
public Integer max
Integer m null;
for int x : ds
if m null x m
m x;
return m;
public long ksumint k
long sum ;
forint i; i iterator
return dsiterator;
Download the Provided Files
The base code for this assignment consists of one zip file, which you can download from Brightspace: compazip source code. This file contains a folder named compa with four java files:
UltraFast.java add your code here
UltraSlow.java
UltraStack.java
Tester.java use this class to design your tests and debugtest your code
Grading
This assignment will be tested and graded by a computer program also known as an autograder. You can submit as many times as you like; your highest grade is recorded. For this to work, there are some important rules you must follow:
Keep the directory structure of the provided compazip file. If you find a file in the subdirectory compa leave it there.
Keep the package structure of the provided zip file. If you find a package compa; directive at the top of a java file, leave it there.
Keep the interfaces as they are. You may add internal methods to your implementation, but do not introduce any new methods to the interfaces.
Do not rename or change the visibility of any methods already present. If a method or class is public leave it that way.
Submit early and often. The autograder will compile and run your code, providing you with instant feedback and a grade. You can submit as many times as you like your final grade will reflect your last submission. Alternatively, you can choose to activate your highestgraded submission as your final score. With this flexibility, there's no excuse for submitting code that doesn't compile or fails the tests.
Similarly to the previous assignments, your methods are not independent and cannot be tested independently.
Start by exploring the skeleton code it includes implementations for all the required methods but is based on a slower model. The Assignment
This assignment contains only one part worth marks.
The data values we will maintain are integers, both negative and positive.
An UltraStack is an extended stack that supports eight main operations: the standard Stack operations push x and pop and the following nonstandard operations:
operatornamegeti: returns the i th element from the bottom on the Stack.
operatornameseti 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 mathrm : returns the maximum value stored on the Stack.
operatornameksumk : 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 set i x each run in O time, but max and ksumk run in On 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 get i and max must be boldsymbolOmathbf and for pushx pop set i x doubleTop swapTop and ksumk running time must not exceed boldsymbolOlog boldsymboln
You may assume that the Stack elements will be in the range
As part of your implementation, you may use any of th hasNext that returns true if this list ite
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
