Stack / Queue - constrained linear table
A. Stack
1. Concept
Data elements last out
In the top of the stack can only insert or remove
a stack of insertions and deletions called pushing and popping
2. storage structure
(1) sequence of stack
Stack / end of stack "pointer" variables may be a pointer or integer variable
The tail end of the stack pointer to the stack
is initially ① NULL, pointer ② -1, shaping
The top element of the stack pointer to the next position, the initial point to the end of the stack
Empty judgment:
①top Base = = NULL, the pointer variable
②top = base = -1, integer variable
Empty judgment choice pseudocode: S.top == 0
(2) link stack (headless node - red):
Just stack pointer
stack pointer to an, an point to aₙ₋₁ ...
3. The application stack
Principle: The current state of the stack with memory function
application: call the function / recursive / parenthesis matching / expression evaluation
⇒ recursive algorithm space complexity is generally 0 (logn), as quick sort
II. Queue
1. Concept
FIFO data elements
front: Team head (remove elements)
REAR: the tail (insert elements)
2. storage structure
2-1 Order - cyclic queue
(1) Team head / tail pointers team
① are integer variables
② queue head pointer always points to the head of the queue element
③ queue tail pointer always points to the next location of the tail element, initially points to the first team: front = rear = 0 (determination Theory empty)
(2) sentence empty:
REAR = Front (requires less declared with an element)
otherwise there may actually be a full team rather than team empty
(3) sentence full (default less space, unless declared with tag):
when the remaining space is allocated memory space in the queue: full team
Analyzing team full: (rear + 1)% m = q.front
(4) the number of elements:
(REAR-fromt the m +) m%
m as (the number of non element) array length
(5) insert, delete elements (default less space)
① inserted (in the tail): rear = (rear + 1 )% m
② Delete (in HOL): front = (front + 1)% m
2-2 chain queue (the head node)
Head-pointer to the first node,
the tail pointer initially points to the first node
determination empty: front = rear
to sum up
1. Pointer
(1) may be sequentially stored in the pointer variable shaping may be used to identify the position
① stack (top element): a pointer variable (textbook)
② queue (queue tail elements): shaping, position identifier (common). Because the circular queue without plastic will be very troublesome
(2) the chain pointer variables are stored
2. tail pointer (top of the stack / queue tail)
(1) are sequentially stored (non-empty): a trailing elements point to the next position
① stack
stack pointer points to the initial end of the stack top = base = Null (textbooks, pointer variable)
Top = Base = -1 (the other, integer variables)
② the tail queue pointer initially points to the first team front = rear = 0 (blank determination theory)
(2) the chain stores: points to the current position of the element (not pointing to the next position)
① stack (without head node): Only a tail pointer stack
② queue (First Node): the tail pointer initially points to the first node
3. test sites
1: is a linear operation restricted nature of tables on stacks and queues