Sunday, October 18, 2009

Pop Stack

Pop stack sends the data in the node at the top of the stack back to the calling algorithm. It then deletes and recycles the node ¾ that is, returns it to memory. After the count is adjusted by subtracting 1, the algorithm returns to the caller. If the pop was successful, it returns true; if the stack is empty when pop is called, it returns false.

algorithm popStack (ref stack ,

ref dataout )

This algorithm pops the item on the top of the stack and returns it to the user.

Pre stack is metadata structure to a valid stack

dataout is a reference variable to receive the data

post data have been returned to calling algorithm

Return true if successful; false if memory underflow

1 if (stack empty)

1 success = false

2 else

1 dltptr = Stack.top

2 dataout = stack.top->data

3 stack.top = stack.top->next

4 stack.count = stack.count – 1

5 recycle (dltptr)

6 success = true

3 end if

4 return success

end popStack

No comments:

Post a Comment