1. Backpack
PS: The data collection for deleting elements is not supported; His purpose is to help the group collect elements and traverse elements.
2. Dijkstra two-stack arithmetic expression
ImportJava.util.*; /*** Each formula must be enclosed in brackets, not good * (2+6* (+) *) *@authorBee **/ Public classmain{ Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); while(Sc.hasnext ()) {Stack<String> Ops =NewStack<>(); Stack<Double> Vals =NewStack<>(); String Str=Sc.nextline (); for(intI=0;i<str.length (); i++) {String s= Str.charat (i) + ""; if(S.equals ("(")){ }Else if(S.equals ("+") {Ops.push (s); }Else if(S.equals ("-") {Ops.push (s); }Else if(S.equals ("*") {Ops.push (s); }Else if(S.equals ("/") {Ops.push (s); }Else if(S.equals (")")) {//pop-up operators and operands, calculation results are pressed into the stackString op =Ops.pop (); Double v=Vals.pop (); if(Op.equals ("+") ) {v= Vals.pop () +v; }Else if(Op.equals ("-") ) {v= Vals.pop ()-v; }Else if(Op.equals ("*") ) {v= Vals.pop () *v; }Else if(Op.equals ("/") ) {v= Vals.pop ()/v; } vals.push (v); }Else{//non-operator and non-parenthesis, directly double pressed into the stackVals.push (double.parsedouble (s)); }} System.out.println (Vals.pop ()); } sc.close (); } }
3.java Data structure
Data structure of Java