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