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.