Help Sorting a List of Numbers

1,894 views
Skip to first unread message
Assigned to scottfr...@gmail.com by me

appguytry2

unread,
Mar 15, 2014, 3:22:09 AM3/15/14
to mitappinv...@googlegroups.com
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

unread,
Mar 15, 2014, 3:32:34 AM3/15/14
to mitappinv...@googlegroups.com

SteveJG

unread,
Mar 15, 2014, 9:00:03 AM3/15/14
to mitappinv...@googlegroups.com
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.

Best regards,
SteveJG

Scott Ferguson

unread,
Mar 15, 2014, 2:49:09 PM3/15/14
to
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.

---

Scott

Sort.aia

phantomfoot

unread,
Mar 15, 2014, 7:47:23 PM3/15/14
to mitappinv...@googlegroups.com
Very well done Scott! Genius

Scott Ferguson

unread,
Mar 16, 2014, 12:36:04 AM3/16/14
to mitappinv...@googlegroups.com
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....
---
Scott

On Saturday, March 15, 2014 6:47:23 PM UTC-5, phantomfoot wrote:
Very well done Scott! Genius

Romulo Marquez

unread,
Mar 25, 2014, 10:29:49 PM3/25/14
to mitappinv...@googlegroups.com
Scott,

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"


Thanks!

Scott Ferguson

unread,
Mar 26, 2014, 12:51:37 AM3/26/14
to mitappinv...@googlegroups.com
Sure. Just put the sort procedure on the same screen and call it with the list attached.
---
Scott

Romulo Marquez

unread,
Mar 27, 2014, 10:14:14 AM3/27/14
to mitappinv...@googlegroups.com
Thank you Scott...

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

Genius!

Enis

unread,
Mar 27, 2014, 12:28:51 PM3/27/14
to mitappinv...@googlegroups.com
Great Romulo... and nice work Scott ;)!
Reply all
Reply to author
Forward
0 new messages