Stack
1.top and bottom. Unity added and removed at top end.
Attention:
The function Delete (x) is to delete the top end element and assign the value to X
Implementation: Implemented through the linked list.
Public classstackli{ PublicStackli () {topofstack =NULL; } Public BooleanIsfull () {return false; } Public BooleanIsEmpty () {returnTopofstack = =NULL; } Public voidMakeempty () {topofstack =NULL; } Public voidpush (object x) PublicObject Top () Public voidPop ()throwsUnderflow PublicObject Topandpop ()PrivateListNode Topofstack; }
implemented through an array.
Main application: For the matching of parentheses try programming because I haven't used stack before.
Several main methods used: Add (x), Pop (), Firstelement ()
Public voidTestmatch (String expression) {Matchstack=NewStack<integer>(); intlen=expression.length (); for(inti=0;i<len;i++){ CharGetch=Expression.charat (i); if(getch== ' (') {matchstack.add (i); }Else if(getch== ') '){ Try{matchstack.pop (); }Catch(Exception e) {System.out.println (i+ "Missing left parenthesis"); } } } while(!Matchstack.isempty ()) {System.out.println (matchstack.firstelement ()+ "Missing right parenthesis"); Matchstack.pop (); } }
Expression: infix expression infix expressions, which we understand in normal sense.
Posfix expression suffix expressions prefix expression prefix expressions
Suffix expression----> infix expression
The specific algorithm see expression conversion essay.
Data Interface review 3 stack and queue