One: The mathematical nature of the stack
When n numbered elements are stacked in a certain order, and can be stacked at any time, the number of numbers ordered by the number of elements n is exactly the sum of the Catalan functions, i.e.
Two: Topic One:
Try to put 1,2,3,4,5,6, six digits into the stack, then there are several ways out of the stack? The use of mathematical properties can be known to have 132
III: Other topics: Judging the legality of the sequence of operations given by the stack
I into the stack o out of the stack, such as ABC into the stack, out of the stack for the CBA, then the given sequence is Iiiooo, indicating 3 first into the stack, and then out of the stack
Now given a sequence (with IO only) to determine whether it is legitimate
Four: Nature
1. Same number of IO
2. Start to middle any position I number is greater than O number
Five: Implementation code
intJudgeCharch[]) { intInp out; inti; INP= out= i =0; while(Ch[i]! =' /') { if(Ch[i] = ='O') out++; ElseINP++; if( out>INP)return 0; I++; } if(INP! = out) return 0; return 1;}
Mathematical properties of stack and queue stack of algorithm exercises---