Data Interface review 3 stack and queue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.