subject

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).

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 14:30
If the polar bear were taken out of the food chain what would happen to the seal population the seal population would diminish the seal population would grow dramatically the seal population would stay the same the seal population would decrease slightly
Answers: 1
question
Computers and Technology, 22.06.2019 17:30
Rachel completed typing an official document with a word processing program. she wants to make sure that her document has no typographical errors. she also wants all headings to have the same font. which features in a word processing program should she use? rachel should use the feature in a word processing program to find typographical errors. she should apply to have uniform headings.
Answers: 1
question
Computers and Technology, 22.06.2019 19:10
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 1
question
Computers and Technology, 22.06.2019 22:10
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
You know the right answer?
Design a stack class by importing the available java. util. Stack to have the following features: p...
Questions
question
History, 27.10.2020 23:20
question
Mathematics, 27.10.2020 23:20
question
Mathematics, 27.10.2020 23:20
question
Mathematics, 27.10.2020 23:20
question
Mathematics, 27.10.2020 23:20
question
German, 27.10.2020 23:20
Questions on the website: 13722363