Geeks With Blogs
Mark Pearl


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.

Posted on Saturday, February 20, 2010 2:41 PM C++ | Back to top

Comments on this post: Stacks in C++

# re: Stacks in C++
Requesting Gravatar...
wazz nan ung hnhnap q d2...??? hmp!!!
Left by jayson on May 03, 2010 6:15 AM

Your comment:
 (will show your gravatar)

Copyright © MarkPearl | Powered by: