0% found this document useful (0 votes)
6 views1 page

Stack Operations: Push, Pop, Display

The document describes three functions for performing operations on a stack: 1) The Push function takes in a value and the stack array, increments the top pointer, and assigns the value to the stack array at the new top position, returning the updated top pointer. 2) The Pop function checks for underflow, displays and removes the value at the top position, and decrements the top pointer, returning the updated top. 3) The Display function uses a while loop to iterate from the top pointer down, outputting each value in the stack array.

Uploaded by

Deepankar Borah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Stack Operations: Push, Pop, Display

The document describes three functions for performing operations on a stack: 1) The Push function takes in a value and the stack array, increments the top pointer, and assigns the value to the stack array at the new top position, returning the updated top pointer. 2) The Pop function checks for underflow, displays and removes the value at the top position, and decrements the top pointer, returning the updated top. 3) The Display function uses a while loop to iterate from the top pointer down, outputting each value in the stack array.

Uploaded by

Deepankar Borah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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