Talk C Chestnut Bar (20th time: C language Instance--bracket matching)

Source: Internet
Author: User


Ladies and gentlemen, hello, crossing, we said the principle of the stack in the first few, and gave the actual example to explain, this time we say the example

The child is: parentheses match. Bracket matching uses the principle of the stack, which can be seen from the examples, so we put them together. Gossip

Hugh, the words return to the positive turn. Let's talk C chestnuts together!


Crossing, the so-called brace matching, is to give a series of parentheses, there are various types of parentheses, and then determine whether the parentheses in the string

is one by one matched. For example: ({[]}) The parentheses in this string are matched. Because the parentheses in the string appear in pairs. ({) This string of parentheses is

is not a match, the string {There is no parentheses paired with it, and the number of matching parentheses is not correct.


In the process of confirming that the parentheses match, our idea is this: first read the parentheses sequentially from the string, reading one parenthesis at a time, such as

The parentheses that are read by the fruit are the opening parenthesis, for example (, {, [, then let the brackets into the stack, if you read the closing parenthesis, for example),},], then the top of the stack

The parentheses are taken out, matched to it, and if matched, proceed to the next parenthesis in the judging string, if it does not match, then it is indicated in the string

The parentheses do not match.


Crossing, the text does not write code, the detailed code put in my resources, you can click the link to download the use.


Crossing, here's an example of matching brackets. I want to know what the following example, and listen to tell.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talk C Chestnut Bar (20th time: C language Instance--bracket matching)

Related Article

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.