2 - Stack Using Array
2 - Stack Using Array
Unit -3
Stack Using Array
Pankaj Chandra
Assistant Professor
IT GGV
Stack using Array
A stack data structure can be implemented using a one-
dimensional array.
Algorithm
Step 1 - Check whether stack is FULL. If (Top == Size of Stack) then
display "Stack is FULL, Insertion is not possible" and Exit.
Step 2 - If it is NOT FULL, then increment Top value by setting
Top=Top+1
Step 3 - Set Stack[top] = ITEM
Step 4 - Exit
Stack Operations using Array - PUSH
Example – Stack is Linear Array Stack of
Size 5.
Initially Top==0 means Stack is empty.
Stack Operations using Array - PUSH
Insert A
Set Top=Top+1 = 1
Set Stack[Top]=A so Stack[1]=A
Stack Operations using Array - PUSH
Insert B
Set Top=Top+1 = 2
Set Stack[Top]=B so Stack[2]=B
Stack Operations using Array - PUSH
Insert C
Set Top=Top+1 = 3
Set Stack[Top]=C so Stack[3]=C
Stack Operations using Array - PUSH
Insert A
Set Top=Top+1 = 4
Set Stack[Top]=D so Stack[4]=D
Stack Operations using Array - PUSH
Insert E
Set Top=Top+1 = 5
Set Stack[Top]=E so Stack[5]=E