A stack is a data structure that holds objects in a last-in, first-out fashion.
A stack has many applications. Java Compiler uses a stack to process method invocations. When a method is invoked, its parameter and local variables are pushed to the stack. When the mentod calls another method, the new method's parameters and local variables are pushed into the stock. When the method finishes its work and return to the caller, its associated space is released.
Exercise: Write a program that implements a stack for storing integers. Stack should internally use an array to hold the elements.
Pushing: 0 1 2 3 4 5 6 7 8 9 Popping: 9 8 7 6 5 4 3 2 1 0
Download Code: Stack of Integers
No comments:
Post a Comment