Algorithm Crash (10) stack

Source: Internet
Author: User

Today to talk about the stack, in the program design, the use of the stack is very extensive, such as the "bracket matching problem", "HTML structure matching problem."

So mastering the "stack" of the use of our learning algorithm is still very helpful.

One: Concept

Stack, also a special linear table, is a form of last in-in-one (LIFO), and there are many examples in reality

For example: a stack of dishes in the cafeteria, we can only take from the top one.

Two: Storage structure

"Stack" is not like "queue", requires two pointers to maintain, the stack needs only one pointer is enough, this benefit from the stack is a constrained linear table.

It also uses the "sequential structure" to store the "stack", with the top pointer pointing to the stack, all of which can only be done at the tops.

Code Snippets:

Data structure of the #region stack   
     ///<summary>   
 ///stack data structure   
 ///</summary> public   
     class seqstack<t>   
     {public   
         t[] data;   
      
         <summary>   
 ///Stack top pointer   
 ///</summary> public   
         int tops =-1;   
      
         Public seqstack (int lenth)   
         {   
             data = new T[lenth];   
         }   
     #endregion

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.