Alright I'm trying to figure out where a stack would be implemented in code. I've been searching around but cannot find a good reason "why" to use a stack. Can anybody help out? Thankx in advance
Alright I'm trying to figure out where a stack would be implemented in code. I've been searching around but cannot find a good reason "why" to use a stack. Can anybody help out? Thankx in advance
"Compilers often use stacks to perform sysntax analysis of language statementns--for example, for loops can contain if then statements that contain while loops that contain for loops. As a compiler works through such nested constructs, it "saves" information about what it is currently working on in a stack. When it fisnishes its work on the innermost construct, the compiler can "retrieve" its previous states from the stack, and pick up where it left off"
C++ Plus Data Structures
>I've been searching around but cannot find a good reason "why" to use a stack.
If you need to simulate an all-you-can-eat buffet then both stacks and queues would be handy.
Your Internet browser forward & back buttons work like a stack. Every time you visit a new page, it gets added to the stack, then when you click the back-button, you work your way back down the stack. As you keep clicking the back-button, the last page (at the bottom of the stack) will be the first page visited. (First-In-Last-Out).
[EDIT]:
Computers use stacks internally too. When multiple levels of interrupts happen, a stack is used so the return-from-interrupts happen in the reverse order of the interrupts.
Function calls are also handled with a stack. One function calls another function, which calls a third, etc. When these functions return, they have to return in reverse order.
Last edited by DougDbug; 09-15-2003 at 12:15 PM.
I don't really remember the details, but I recently read up on Maze Generating algorithims and In each case either a stack or queue was used to store information about the nodes.