Sorting a collection

About Monkey 2 Forums Monkey 2 Programming Help Sorting a collection

This topic contains 3 replies, has 3 voices, and was last updated by  Jesse 2 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5404

    Ethernaut
    Participant

    How do I sort a collection, like a stack?
    I’m thinking of something like this, except this obviously doesn’t work…

    Extended question: can I do it in monkey2 without extending the stack class, passing a function as an argument? How? I get confused because, in my example, the function that compares values requires you to specify the objects being compared, but how would I know those objects inside a For/Next loop, for each loop?

    #5405

    Ethernaut
    Participant

    Never mind, I got this… sorted out 😉
    A quick look at the source code for stacks showed me what to do. No need to extend the Stack class:

    New features like this (compared to Monkey1) are powerful, but are definitely counter-intuitive for noobs, and will take a while to wrap my head around it…

    I find that simply overriding a “Compare” method would have been easier to read!

    #5409

    nerobot
    Participant

    More docs are needed here. 🙂

    #5414

    Jesse
    Participant

    There is also a sort with custom “Function” as a parameter for stacks.

    >More docs are needed here.

    Definitely!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.