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, 24.06.2019 00:50
Which player type acts on other players? a. killer b. achiever c. explorer d. socializer
Answers: 1
question
Computers and Technology, 24.06.2019 08:00
How can smart devices benefit businesses, organizations, and social communities in the global marketplace?
Answers: 1
question
Computers and Technology, 24.06.2019 13:20
3. ranga ramasesh is the operations manager for a firm that is trying to decide which one of four countries it should research for possible outsourcing providers. the first step is to select a country based on cultural risk factors, which are critical to eventual business success with the provider. ranga has reviewed outsourcing provider directories and found that the four countries in the table that follows have an ample number of providers from which they can choose. to aid in the country selection step, he has enlisted the aid of a cultural expert, john wang, who has provided ratings of the various criteria in the table. the resulting ratings are on a 1 to 10 scale, where 1 is a low risk and 10 is a high risk. john has also determined six criteria weightins: trust, with a weight of 0.3; quality, with 0.2; religious, with 0.1; individualism, with 0.2; time, with 0.1; and uncertainity, with 0.1. using the factor-rating method, which country should ranga select? why? (2 points)
Answers: 3
question
Computers and Technology, 24.06.2019 23:30
Does anyone have the problem where you try to watch a video to get your answer but it brings up a thing asking your gender to make ads relevant but it doesn't load? btw i won't be able to see the answer so use the comments .
Answers: 1
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, 11.08.2021 01:00
question
Mathematics, 11.08.2021 01:00
question
Mathematics, 11.08.2021 01:00
question
Social Studies, 11.08.2021 01:00
question
Social Studies, 11.08.2021 01:00
question
Mathematics, 11.08.2021 01:00
Questions on the website: 13722361