Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for deleting an element from stack using array in dfs (data file structure).

  Shared By: Binge Fischer    Date: Nov 17    Category: C++ Programming    Views: 5222

Answer:

PROCEDURE DELETE(ITEM, STACK, TOP)
[Deletes ‘item’ from the ‘stack’, top is the number of elements currently in ‘stack’.]

1. [Underflow ?]

if (TOP <= 0)
write Stack is empty.
return.

2. [Deleting Element]

item <-- stack[top]

3. [Decrementing top]

top <-- top - 1

4. [FINISH]
return (top).

Share: 
 


Related Topics:

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: