N00B question about stacks

This is a discussion on N00B question about stacks within the C++ Programming forums, part of the General Programming Boards category; Alright I'm trying to figure out where a stack would be implemented in code. I've been searching around but cannot ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    2

    N00B question about stacks

    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

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    "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

  3. #3
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    >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.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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 01:15 PM.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very sorry, but this must be the most n00b question =]
    By Teh_n00b in forum C++ Programming
    Replies: 24
    Last Post: 01-23-2007, 07:46 PM
  2. N00b question
    By mightymike in forum Windows Programming
    Replies: 3
    Last Post: 08-25-2006, 05:26 AM
  3. question about stacks (and vectors too for that matter)
    By Silvercord in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2003, 12:26 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21