subject

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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 02:00
Which demographic challenge is europe currently experiencing? a. an aging and decreasing population b. a baby boomc. an unequal distribution between males and females d. a large group of teenagers moving through the school system(i chose a but i'm unsure)
Answers: 1
question
Computers and Technology, 23.06.2019 18:00
Freya realizes she does not have enough in her bank account to use the debit card. she decides to use a credit card instead. which questions should freya answer before using a credit card? check all that apply. can i pay at least the minimum payment each month? can i make payments on time and avoid late fees? will i have to take out a loan? how much in finance charges can i afford to pay? should i talk to a consumer credit counseling service?
Answers: 1
question
Computers and Technology, 24.06.2019 17:00
The length of time that a slide appears before automatically advancing to the next slide can be set in the timing group under the transitions tab. transition to this slide group under the transitions tab. timing group in the master slide view. transition to this slide group in the master slide view.
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
You work in the accounting department and have been using a network drive to post excel workbook files to your file server as you complete them. when you attempt to save a workbook file to the drive, you see the error message: “you do not have access to the folder ‘j: \’. see your administrator for access to this folder.” what should you do first
Answers: 2
You know the right answer?
Same problem as Problem 1 however you will implement the opposite of a MaxStack, namely MinStack. De...
Questions
question
Mathematics, 15.05.2021 22:30
question
Mathematics, 15.05.2021 22:40
Questions on the website: 13722362