2017년 6월 8일 목요일

Help Sorting a List of Numbers


I have 4 scores(group of numbers with no commas or decimals) in a list.  I need to sort the list from highest number to lowest number.

Can I sort the list like this?  If so then How?

--
phantomfoot provided links to two great solutions.  Both solutions are in AI Classic code.   If someone translates these sorting algorithms to AI2, PLEASE return here and consider sharing your code.  The AI2 team has a category for Tips and Tricks.  An AI2 version of these sorting routines would be great to post there.   Or, consider writing a tutorial..we are looking for tutorials too.

--
Here ya go...
This is the same sorting method (optimized bubble sort) that I use in my Flood fill project.
It was faster than the insertion sort that I tested.
Why is this faster than the standard bubble sort?
With bubble sort, the entire list is scanned each time until there are no swaps.
This optimized bubble sort keeps track of were a swap last occurred and sets that as the new end of the list!
So if the last swap was in the middle of the list, only one-half of the list  will be scanned after that.
--
Very well done Scott! Genius

--
Thanks, but I cannot take credit for the algorithm optimization.
I found it on the Internet because some nice person was willing to share it :)
I don't remember where I found it tho....

--
It is possible to do these sorting algorithms in the same screen?

I would like to do the calculate in the same screen!

In other words using a "call procedure"

--
Sure. Just put the sort procedure on the same screen and call it with the list attached.

--
Thank you Scott...

The apk is working very very well!! and in the same screen!!!!  :)

Genius!

--
Great Romulo... and nice work Scott ;)!

--

댓글 없음:

댓글 쓰기