-
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.
-
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?
-
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.
-
stacks in general as a data structure.
-
The STL has a stack template.
-
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?
-
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.
-
Cool. Easier to make your own tree class I think. Any other natty ADTs that the STL provides that I should know about?