Stacks POP 1opS=3→ 956 15
Stacks 6 15 9 5 S top[S] = 3 POP
Stacks topS]=6→3 push 8 12 PUSH 12 856 PUsh 3 15
Stacks 6 15 8 5 3 12 S top[S] = 6 PUSH 8 PUSH 12 PUSH 3
Stacks topS]=6→3 LIFO last-in, first-out 12 856 Underflows If an empty stack is popped Overflows 15 If tops exceeds n
Stacks 6 15 8 5 3 12 S top[S] = 6 Underflows If an empty stack is popped. LIFO last-in, first-out Overflows If top[S] exceeds n
Stacks STACK-EMPTY(S) 1. if tops=0 2. then return trUe topS]=6→3 3. else return FALSE 12 PUSH(S, x) 1.top{S←top[S]+1 856 2.S[top[S]←x POP(S 1. if STACK-EMPTY(S) 15 2. then error"underflow 2. else top|S]←top[S] return Stops+
Stacks 6 15 8 5 3 12 S top [ S] = 6 STACK-EMPTY ( S) 1. if top [ S] = 0 2. then return TRUE 3. else return FALSE PUSH ( S, x ) 1. top [ S] ← top [ S] + 1 2. S [top [ S]] ← x POP ( S) 1. if STACK -EMPTY ( S) 2. then error "underflow" 2. else top [ S] ← top [ S] − 1 4. return S [top [ S] + 1]
Queues 12345678910 heade=taill=1
Queues 1 2 3 4 5 6 7 8 9 10 Q head[Q] = tail[Q] = 1