Application of the brackets in C ++ --- matching brackets

Source: Internet
Author: User

Application of the brackets in C ++ --- matching brackets

At the beginning, I learned the data structure and wrote a classic application using the delimiter, matching the brackets.


Algorithm ideas:

When you input a string, press '(', '[' into the sequence, and then press ') ''']' to stack the sequence and perform matching by parentheses. If the matching is successful, otherwise, the program ends and the mismatch information is entered,

If ') '']' matches all, it determines whether the Delimiter is null. If it is null, the input matches. Otherwise, the number of output symbols does not match.


# Include
 
  
Using namespace std; # define max 100 struct stack {int Top; int MaxSize; char * element;}; typedef struct stack Stack; void Init (Stack * S, int n) {if (n> 0) {S-> Top =-1; S-> MaxSize = n; S-> element = new char [S-> MaxSize];} bool IsFull (Stack * S) {return (S-> Top = S-> MaxSize-1);} bool IsEmpty (Stack * S) {return (S-> Top =-1);} void push (Stack * S, char x) {if (! IsFull (S) S-> element [++ S-> Top] = x; else {cout <"full" <
  
   
Element [S-> Top --]; else {cout <"empty" <
   
    
They are simple definitions and functions.

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.