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)