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, 22.06.2019 17:00
1. so if i wanted to build a linux server for web services(apache) with 1cpu and 2 gb of memory.-operating at 75% of memory capacity2. a windows server with 2 cpu/ 4gb memory- operating at 85% of memory capacity3. a storage server with 1 cpu/ 2gb memory- operating at 85% of memory capacityhow much memory do i have to add for each server.so that the utilization rate for both cpu and memory is at a baseline of 60%."the details for the cpu like its processor or the memory's speed isnt to be concerned" yeah i kept asking my teacher if he's even sure about the but the whole class seems to be confused and the project is due in 3 days..this is a virtualization project where i have to virtualize a typical server into an exsi hypervisor.
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
What does 21 pilots middle aged name as a band 15 years prior to them naming their band 21 pilots?
Answers: 1
question
Computers and Technology, 24.06.2019 11:00
Why is it uncommon for users to perform searches directly in database tables? a.)users are discouraged from interacting directly with tables because they might confuse tables with spreadsheets. b.) users are discouraged from interacting directly with tables because this may result in unintended changes to source data. c.)users do not have the technical skills required to perform searches directly in database tables. d.)users do not have the permissions required to perform searches directly in database tables.
Answers: 1
question
Computers and Technology, 24.06.2019 18:30
Jacking is a crime that takes place when a hacker misdirects url to a different site. the link itself looks safe, but the user is directed to an unsafe page
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, 10.11.2019 21:31
question
Geography, 10.11.2019 21:31
question
Mathematics, 10.11.2019 21:31
Questions on the website: 13722360