...

View Full Version : STL Stacks



justinhull
11-10-2004, 11:35 PM
I have a question about the STL stack member:
bool operator < (const stack&, const stack&)

In the STL description it says "Lexicographical ordering of two stacks."

anyone think they could explain how exactly this determines which stack is greater/less than the other? I'm just lost on this one.

Thanks

Mhtml
11-10-2004, 11:55 PM
Well this is usually in terms of a recursive function. (I've never actually used STL though) Each item in the stacks are compared to each other. If the first match, it moves to the second, if the second match onto the third and so on untill a result is happend on or the stack is depleted.

You do understand how the prototype works right?

justinhull
11-11-2004, 12:18 AM
no not really, I grasp the whole stack concept and I know how to use them, I just don't really understand how it is compared, like if there were 2 integer stacks.

stack a:
1 top()
2
3

stack b:

2 top()
6
4

what would a<b return?

Mhtml
11-11-2004, 12:35 AM
Yeah it would.

The prototype is just overloading the < operator as a function name.

[edit:] lol, just reread your question... and the answer is the question, which is why I gave a weird answer.

a<b would return a<b .. The prototype says it returns a boolean so it would return true because a is < b.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum