posts - 293 , comments - 426 , trackbacks - 0

My Links

News

View Steve Michelotti's profile on LinkedIn

Twitter












Tag Cloud

Archives

Post Categories

My Online Presence

Stacks in C++

 

A stack is a LIFO (last in first out) data structure. A stack has at least two basic method calls – push & pop. Push, “pushes” an item on the top of the stack. Pop, removes the top most item off the stack.

Implementation of Stacks as Arrays

Because all elements on a stack are of the same type, one can use an array to implement a stack. The first element in a stack would be the first element in the array, the second on the stack would be the second on the array, etc.

Linked Implementation of Stacks

One limitation with an array implementation of a stack is that unless the array is dynamic, one would have to have a preset max stack size (based on the bounds of the array).

We saw with linked lists, that pointers allow us to dynamically grow or shrink a collection of data, and this principle can be applied to implement a dynamic stack size.

Application of Stacks

Stacks have many applications… a typical computer science example would be Postfix Expression Calculator, where the LIFO principle is maintained.

Print | posted on Saturday, February 20, 2010 2:41 PM | Filed Under [ C++ ]

Feedback

Gravatar

# re: Stacks in C++

wazz nan ung hnhnap q d2...??? hmp!!!
5/3/2010 6:15 AM | jayson
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 
 

Powered by: