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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:00, razielcornils04
What is the algorithm for building a binary tree program
Answers: 2
image
Computers and Technology, 22.06.2019 11:00, bombbomb2157
Eva has many contacts on the professional networking site she uses which contacts are considered second degree
Answers: 3
image
Computers and Technology, 24.06.2019 00:00, Amrinderkhattra
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
image
Computers and Technology, 24.06.2019 14:00, ameliaxbowen7
Which computer tools allow you to communicate with coworkers, family, and friends
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 in other subjects:

Konu
Mathematics, 20.09.2020 05:01
Konu
History, 20.09.2020 05:01