Class MinStack#9035

Class MinStack

7 seconds
128 megabytes
Easy

Implement a stack data structure that supports next operations:

Write the code according to the next interface:

class MyStack // C++
{
private:
  stack<int> s, mn; // s - normal stack, mn - minimum stack
public:
  void push(int x); // Push x into the stack
  int pop(void); // Remove and return the element from the top of the stack
  int top(void); // Return the element from the top of the stack
  int GetMin(void); // Return the minimum element from the stack
  int GetSize(void); // Return the size of the stack
};
class MyStack // Java
{
  private stack<Integer> s, mn; // s - normal stack, mn - minimum stack
  MyStack() // Constructor
  public void push(int x); // Push x into the stack
  public int pop(void); // Remove and return the element from the top of the stack
  public int top(void); // Return the element from the top of the stack
  public int GetMin(void); // Return the minimum element from the stack
  public int GetSize(void); // Return the size of the stack
};

Input

Each line contains a single command.

Output

For each command print on a separate line the corresponding result.

Examples

Example 1

Loading
Loading