Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: STL Stacks

  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    STL Stacks

    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

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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?
    Omnis mico antequam dominus Spookster!

  • #3
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Last edited by justinhull; 11-10-2004 at 11:19 PM. Reason: grammar

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Last edited by Mhtml; 11-11-2004 at 01:58 AM.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

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