Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to sort a list greatest to least
- lightningtow
- Scratcher
39 posts
How to sort a list greatest to least
I have a game in which I need to sort a list greatest to least, can anybody please help me?
In case anyone was wondering, my profile picture is an epic face wearing an Assassin's Creed hood. With some knives.
There are two secrets to great success in life.
1) Never share all you know.
- eaglgenes101
- New to Scratch
100+ posts
How to sort a list greatest to least
If it's a small list, then use insertion sort.
If it's larger, use quicksort or mergesort.
Quicksort works like this: Take the first element in a list. Put all greater than it before it, all less after it. Repeat this process on any sublist that forms.
Mergesort is this: Split the list into 2-length lists. Sort each of these, then join them into 4-length lists, sort them, and repeat this joining and sorting until you have a sorted list.
If it's larger, use quicksort or mergesort.
Quicksort works like this: Take the first element in a list. Put all greater than it before it, all less after it. Repeat this process on any sublist that forms.
Mergesort is this: Split the list into 2-length lists. Sort each of these, then join them into 4-length lists, sort them, and repeat this joining and sorting until you have a sorted list.
- lightningtow
- Scratcher
39 posts
How to sort a list greatest to least
Never Mind, I got it.
Last edited by lightningtow (Aug. 21, 2013 02:34:32)
In case anyone was wondering, my profile picture is an epic face wearing an Assassin's Creed hood. With some knives.
There are two secrets to great success in life.
1) Never share all you know.
- Discussion Forums
- » Help with Scripts
- » How to sort a list greatest to least