Results 1 to 8 of 8

Thread: Stacks?

  1. #1
    Guest
    A stack is kind of like a pile of dishes:

    When you put one on, that will be the first taken off:

    Code:
    3rd put on.
    2nd put on.
    1st put on.
    As you can see, the third is on top.


    Code:
    Push something onto stack:
    
    4th put on.
    3rd put on.
    2nd put on.
    1st put on.
    Code:
    Pop something off the stack:
    stack:                      Value returned:
    
    3rd put on.               4th put on.
    2nd put on.
    1st put on.

  2. #2
    Member
    Join Date
    Sep 2000
    Location
    New Hampshire
    Posts
    32
    ok thats a bit more clearer now.
    what would be the purpose of such a way as stacking?
    I just would not know waer to apply this method too.

    would it be used around true conditions or what?

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Stacks are useful for recursion. To totally understand how they apply to this you need to know how C uses return values. The return value is stored in the register EAX on the processor. Each time you call the function, it pushes it onto a stack, so that you "unwind" the stack to go back through the functions collecting the return values in order.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Guest
    stacks in general as a data structure.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The STL has a stack template.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    STL has a lot of handy templates doesn't it? A list template too, if I remember. I don't suppose there's a tree template too? And a queue?
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I don't think it has a specific tree, but you can get make one by using list<list<int> > or similar (remembering the space between > and >).

    There is a queue, and also something called priority_queue which is a sorted queue.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Cool. Easier to make your own tree class I think. Any other natty ADTs that the STL provides that I should know about?
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width