Data Structure

Stack

Learn data structure by example for stack algorithm

4/26/2021
0 views
stack-algorithm.cC
/* Push */
If (TOP == MAX) Then	[Check for overflow]
	Print: Overflow
Else
	Set TOP = TOP + 1	[Increment TOP by 1]
	Set STACK[TOP] = ITEM	[Assign ITEM to top of STACK]
	Print: ITEM inserted
[End of If]
Exit

/* Pop */
If (TOP == 0) Then	[Check for underflow]
	Print: Underflow
Else
	Set ITEM = STACK[TOP]	[Assign top of STACK to ITEM]
	Set TOP = TOP - 1	[Decrement TOP by 1]
	Print: ITEM deleted
[End of If]
Exit
data structurealgorithmstack data structurestack algorithm

Loading comments...

Related Examples