Computers and Technology

Design a stack class by importing the available java. util. Stack to have the following features: push(x) -- push element x onto stack, where x is anywhere between Integer. MIN_VALUE and Integer. MAX_VALUE.
pop() -- remove the element on top of the stack.
top() -- get the top element.
getMax() -- retrieve the max element in the stack in constant time (i. e., O(1)).
Your code should have the following shape and form, all in one .java file. Note the styling and documentation API already included for the target class, MaxStack:
import java. util. Stack;
public class HomeworkAssignment1_1 {
public static void main(String[] args) {
// Your main() is not graded so you can
// have any implementation in this area
MaxStack obj = new MaxStack();
obj. push(12);
obj. push(1);
obj. push(-12);
obj. pop();
System. out. println(obj. top());
System. out. println(obj. getMax());
// etc.
}
}
/**
* The MaxStack program implements a Stack class with the following features:
* push(x) -- push element x onto stack
* pop() -- remove the element on top of the stack
* top() -- get the top element.
* getMax() -- retrieve the max element in the stack in constant time (i. e., O(1)
*/
class MaxStack {
// Initialize your data structure in constructor
// or here; choice is yours.
public MaxStack() { // YOUR CODE HERE }
public void push(int x) { // YOUR CODE HERE }
public void pop() { // YOUR CODE HERE }
public int top() { // YOUR CODE HERE }
public int getMax() { // YOUR CODE HERE }
}
EXAMPLES
MaxStack maxStack = new MaxStack();
maxStack. push(-2);
maxStack. push(0);
maxStack. push(-3);
maxStack. getMax(); // returns 0
maxStack. pop();
maxStack. top(); // returns 0
maxStack. getMax(); // returns 0
CONSTRAINTS AND ASSUMPTIONS
For this problem you are ONLY allowed to use Java's reference class Stack (Links to an external site.). Failure to do so will receive 5 points off.
MaxStack does not mean elements have to be ordered in increasing or decreasing values in the Stack.
HINTS
You solution should persist a global max value while maintaining the ability to transact on a java. util. Stack instance wrapped in your MaxStack class.
When implementing the MaxStack methods, you will have to invoke your Java stack instance's comparable methods (naming convention may be different).

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 11:30, kyraj21
Which excel file extension stores automated steps for repetitive tasks?
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, erjalinalii
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
Answers: 2
image
Computers and Technology, 24.06.2019 01:30, BIKRAMlawati5544
Could you find out how im still getting an 83 percent on this in edhesive a = input("enter an animal: ") s = input ("enter a sound: ") e = "e-i-e-i-o" print ("old macdonald had a farm, " + e) print ("and on his farm he had a " + a + "," + e) print ("with a " + s + "-" + s + " here and a " + s + "-" + s + " there") print ("here a " + s+ " there a " + s) print ("everywhere a " + s + "-" + s ) print ("old macdonald had a farm, " + e)
Answers: 2
image
Computers and Technology, 24.06.2019 16:00, bsrlee1115
Which type of cloud computing offers easily accessible software and applications on the machines
Answers: 1
Do you know the correct answer?
Design a stack class by importing the available java. util. Stack to have the following features: p...

Questions in other subjects:

Konu
Social Studies, 18.07.2019 20:00