"Go" Basics series 3--stack (code not yet written)

Source: Internet
Author: User

Original address: http://www.cnblogs.com/mcgrady/p/3213289.html

On a summary of the list of linear table, this article we want to summarize is the stack, I would like to summarize from the following aspects.

1, what is a stack?
2, the storage structure of the stack?
3, the common operation of the stack and code implementation?

1. What is a stack

The first stack is a special linear table. So where does it manifest its specificity? A stack is a linear table that restricts insertion and deletion operations at one end of a table, so the stack is also known as a linear table of last-in, first-out (LIFO).

It has a lot of application scenarios, such as a stack of dishes in the canteen, we can only take from the top of one place.

2. Storage structure of stacks

3. Common operations and code implementations of stacks

1, initialize

Implementation idea: Instantiate a seqstack<t> with length of the specified size, and then point the top pointer to-1.

2, into the stack

Implementation idea: Add the top pointer to 1 and insert the new node into the position where the top pointer is pointing.

3, out of the stack

The idea: eliminate top-pointing nodes and reduce the top pointer by 1.

4, get the top element of the stack

Implementation ideas: Similar to the stack, just do not change the state of the stack.

5, determine whether the stack empty

Implementation idea: If the top pointer is equal to-1, then the empty stack is returned if it is.

6 to determine if the stack is full

Implementation idea: Check that the value of the top pointer is equal to the length of the array, and if so, the stack is full.

Code implementation:

"Go" Basics series 3--stack (code not yet written)

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.