Wednesday, February 25, 2009

116B Survey KH34

Stack Data Structure

- a stack is a limited version of an array. New elements or nodes as they are often called, can be added to a stack and removed from a stack only from one end. For this reason, a stack is referred to as a LIFO structure (Last-In First-Out).

Explainations on the steps involve in consicutively accomodating the stack data structure:

1. Stack can be stored in a static or dynamic data structure.
2. Create your stack.
3. When you put/push data 1 in a stack, the isFULL operation will check if there is still a space for the data 2 and data 3 that you'll going to push after data 1.
4. Next add data 2 in the stack.
5. The total++ operation will total how many data that you push.
6. Add data 3 in the stack.
7. The total++ operation will total how many data that you push.
8. Now by following the LIFO(Last In First Out), you are going to pop the data 3 that you push last. The operator isEMPTY will check if your stack is empty.
9. After removing the data, the stack total will update your total stack.

Example:

create stack
push A onto stack
push F onto stack } you're stack have data A, F, and X
push X onto stack
pop item from stack=> pop data A from your stackpush B onto stackpop item from stackpop item from stack

No comments:

Post a Comment