GITHUB:HTTPS://GITHUB.COM/CBAMLS
Welcome to join (Java) National Schools IT elite QQ Group number: 467123855
Package com.offer.chapter1;
Import Java.util.Stack; /** * Copyrright (c) 2014-2016 haerbin hearglobal co.,ltd * Project:demo * Comments: * Author:cbam * Create date:2017 /2/4 * Modified by: * Modified Date: * Modified Reason: */public class Problem_01_mystack1 {private Stack<int
Eger> Stackdata;
Private stack<integer> stackmin;
Public Problem_01_mystack1 () {this.stackdata = new stack<> ();
This.stackmin = new stack<> (); public int Getmin () {if (This.stackMin.isEmpty ()) {throw new RuntimeException (' Your stack is E
Mpty ");
return This.stackMin.peek ();
public void push (int newnum) {if (This.stackMin.isEmpty ()) {This.stackMin.push (newnum);
else if (Newnum <= this.getmin ()) {This.stackMin.push (newnum);
} this.stackData.push (Newnum);
public int Pop () {if (This.stackData.isEmpty ()) { throw new RuntimeException ("Your stack is empty");
int value = This.stackData.pop ();
if (value = = This.getmin ()) {This.stackMin.pop ();
return value; }
}