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)