Home > Back-end >  4.3 stack study notes
4.3 stack study notes

Time:11-15

Stack, a constrained linear table operation, only allow the insertion and deletion of the end
Note: shape and operation, it is very similar to a tired up the dishes we
1. Why do you want to use the stack, the constrained linear table operation, direct use of arrays and linked list is not to go, more and more flexible operation?
Answer: use function, can really use arrays and linked list instead of the stack, but the specific data structure is of certain scenes of abstraction, and array lists exposed too much operation interface, flexible operation, use is not controllable, more error-prone nature
Note: there is significant, there are specializing in, more efficient and low fault, also explains the stack is the specific use of inherited abstract, arrays and linked list is abstract
2. The usage scenarios and implementation stack
A: only in a data set, only at one end inserted delete data, and last in first out (reverse) characteristics, stack implementations are available, and the structure of the array called sequential stack, chain table structure called chain stack
3. The order of the expansion and dynamic stack
Answer: the principle of expansion and directly from the dynamic array, the space is not enough, when applying for a larger space, and then copy the data in the past, therefore, the best stack time complexity o (1), the worst o (n) is the capacity to move because it is over, but the average is o (1), available capitation method argument (in most cases o (1) rarely o (n))
Note: a full stack k, 2 k to apply for a new space, split into the stack operation of k + k, o (1)
4. Operating out of the stack into the stack
Only support into the stack operation, and can be achieved by an array of linked list, so is a constrained linear table structure, operation characteristic lifo
Note: top pointer has been a virtual point,
Arr [top++]=x;
Arr [- top]=x;
5. Classic stack using
A. stack applied in the function call
Executed in accordance with the input before, first perform the function only when the internal call other functions are executed before (JVM memory management concept of stack, stack method is used to save local method and the method of the local variable), recursive implementation is also, by calling a function of the scope of the local variable is (local method calls, the variables to establish the function, at the end of the called function, return to the calling function), recursive
B. the stack in the expression evaluation application
Operators have priority, need to reverse, the double stack to achieve
Stack rules: data directly into the stack, stack operation only the higher priority to get (ensures priority output)
The stack rules: only when the operation stack cannot enter (operator) into less than equal to stack operator, pop-up operation stack, until can enter; The Numbers stack two a pop-up, perform digital into the stack after
Parentheses processing: can put the right parenthesis is regarded as the highest priority
C. the stack in parentheses matching application
Right left into the stack, right out of the stack and found an empty
6. The browser forward backward operation principle
Do you want to implement in a series of into the stack operations, kept this a few pages, you need to stack x, the stack y, so need to double stack implementations, x is responsible for the backward pop-up, stack y responsible for forward pop-up
Note:
Responsible for the page forward reverse operation, exit the reverse operation, need to double stack
X is responsible for the user to see into the stack, back out of the stack operation;
Y responsible for x out of the stack data into the stack, forward operating out of stack
Two-way linked list also can achieve the same function

CodePudding user response:

If only stick point to understand the code gnome male -"

CodePudding user response:

If only stick point to understand the code gnome male -"
  • Related