Write the steps involved in the insertion and deletion of an element in the stack.

Category: Data StructureWrite the steps involved in the insertion and deletion of an element in the stack.
1 Answers
Editor">Editor Staff answered 2 years ago

Push:
Increment the variable top so that it can refer to the next memory allocation
Copy the item to the at the array index value equal to the top
Repeat step 1 and 2 until stack overflows

Pop:
Store the topmost element into the an another variable
Decrement the value of the top
Return the topmost element