Stack

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

1) Push(top,pushd_value,stack_arr)

Let(1)top be any integer datatype initialized with -1 value.


(2)”pushd_value”is any integer value to be pushed in stack.
(3)satck_arr is the name of array.
STEP 1:BEGIN
STEP 2:If Top=(high-1)[if the value of top is equal to High-1(here High is the value of
top most place in stack)]
(1)stack overflow
END IF
STEP 3:Else
(1) top=top+1[increase the value of top by 1]
(2) stack_arr[top]=pushd_value[assign value of pushd_value to array named
stack_arr]
END ELSE
STEP 4:Return Top
STEP 5:STOP

2)Pop(Top,stack_arr)
Let(1)”Top” be any integer datatype initialized with -1 value.
(2)let stack_arr is the name of the array.
STEP 1:BEGIN
STEP 2:if top=-1[if the value of top is equal to -1] then
(1) the stack is underflow.
END IF
STEP 3:ELSE
(1)display the array of top value[the value deleted is,stack_arr[top]]
(2)top-1[decrease the value of top by 1]
END ELSE
STEP 4:return Top
STEP 5:STOP

3)Display(top,I,stack_arr)
Let (1)”Top” be any integer datatype initialized with -1 value.
(2)i is the integer executed in loop structure.
STEP 1:BEGIN
STEP 2: While I>=0 [until the value of I is greater then or equal to 0]
I=Top [assign the value of top to i[i=Top]
And (I-1)[decrease the value of I by 1]
Write the value of stack_arr[I]
END LOOP
STEP 3:STOP

You might also like