Computers and Technology
Computers and Technology, 19.03.2021 18:00, lexis1446

Same problem as Problem 1 however you will implement the opposite of a MaxStack, namely MinStack. 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.
getMin() -- retrieve the min element in the stack in constant time (i. e., O(1)).
Your code should have the following shape and form:
import java. util. Stack;
public class HomeworkAssignment1_2 {
public static void main(String[] args) {
// just like Problem 1, whatever you need here
// etc.
}
}
// JUST LIKE ANY PROBLEM, YOUR STYLING AND DOCUMENTATION GOES HERE
// SEE PROBLEM 1 FOR EXAMPLE.
class MinStack {
// Initialize your data structure here
public MinStack() { // 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 getMin() { // YOUR CODE HERE }
}
EXAMPLES
MinStack minStack = new minStack();
minStack. push(-2);
minStack. push(0);
minStack. push(-3);
minStack. getMin(); // returns -3
minStack. pop();
minStack. top(); // returns 0
minStack. getMin(); // returns -2
CONSTRAINTS AND ASSUMPTIONS
For this problem you are ONLY allowed to use Java's reference class Stack . Failure to do so will receive 5 points off.
MinStack does not mean elements have to be ordered in increasing or decreasing values in the Stack.
You solution should persist a global min value while maintaining the ability to transact on a Stack data structure wrapped in your MinStack class

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 15:00, Siris420
Plz ( which is an example of a good url?
Answers: 1
image
Computers and Technology, 23.06.2019 16:30, saintsfan2004
How to do this programming flowchart?
Answers: 3
image
Computers and Technology, 23.06.2019 16:30, 19thomasar
How to do this programming flowchart?
Answers: 3
image
Computers and Technology, 24.06.2019 00:00, marika35
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
Do you know the correct answer?
Same problem as Problem 1 however you will implement the opposite of a MaxStack, namely MinStack. De...

Questions in other subjects:

Konu
Mathematics, 30.09.2020 04:01
Konu
History, 30.09.2020 04:01