Mathematical properties of stack and queue stack of algorithm exercises---

Source: Internet
Author: User

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---

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.