1. The basic concept of stack
Stack is restricted to only at one end for insertion and deletion of the linear table, often refer to insert, delete to the end of the stack, on the other side of the bottom of the stack, while there is no element in the table is called an empty stack, stack element is always after being inserted element, which is also the first to be deleted elements; Is always the first to be inserted into the bottom of stack elements, which is also the last to be deleted elements, the stack is in accordance with the "advanced" or "last in, first out" principle of organizing data,
2. The order of the stack storage and computing
Using a one-dimensional array S (1: m) as the order of the stack storage space, which m for maximum capacity,
In the order of the stack storage space (1: m), S
S (bottom) to the bottom of the stack elements, S (top) as the stack elements, top=0
The stack is empty; Top=m said stack up,
Stack, there are three basic operations: stack, stack back and read the top element,
Operation: (1) into the stack into the stack operation refers to insert a new element at the top of the stack location, first add a stack pointer (that is, the top
+ 1), then insert the new element to the stack pointer to the location of the, when the stack pointer is pointing to the storage space of the last bit
The rear, the stack space is full, can't again into the stack operation, this is called a stack overflow "mistakes",
(2) check out stack operation: return stack refers to remove the stack elements and assigned to a specified variable, refers to the first element in the stack (stack
Needle points to the element) is assigned to a specified variable, then the stack pointer minus one (top 1), when the stack pointer is 0,
Illustrate the stack is empty, not for return stack operation, this kind of situation is called stack underflow "error,
(3) read the stack elements: stack element refers to the stack element is assigned to a specific variable, the operation does not delete the top
Elements, but it is assigned to a variable, so the stack pointer won't change, when the stack pointer is 0, illustrate the stack is empty, can't read
The top element,
Tip: the stack is in accordance with the "advanced" or "last in, first out" principle of organizing data, but there are so many choices out stack way, in the examination questions often examines a variety of different ways of the stack,