• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting handler


  • Subject: Re: Sorting handler
  • From: has <email@hidden>
  • Date: Fri, 28 Sep 2001 17:22:09 +0100

Hi all,

Arthur suggested I post my modified version of his class deletion-based
sort as he's a bit tied up with other stuff at the moment. Sorry about the
total lack of commenting - this wasn't really intended for public
distribution. (If anyone jumps up and down enough I can probably be
persuaded to address this.)

My contribution is in the inner repeat loop: rather than scan back through
the list to find the insertion point as in Arthur's original, this one
jumps around like a little mad thing ('binary insertion', as Arthur put it)
til it finds the right spot. As with Arthur's original, the handler is
class-sensitive. This one sorts a list of numbers; for strings you have to
amend lines 2 and 22 to:

set lst to {""} & lst

set lst to ((lst's items 1 thru o) & v & (lst's items (o + 1) thru -1))'s
strings

Have fun,

has


p.s. Watch for the special characters and wrapped lines below.

(p.p.s. You'll notice I've now amended my ScriptToEmail script to write
keyboard combos as uppercase, e.g. "[OPT-,]" rather than "[opt-,]" for
better readability. Are these clear enough?)

======================================================================

on SortedNumbers(lst)
set lst to {-1.0E+18} & lst
repeat with i from 3 to lst's length
if lst's item i < lst's item (i - 1) then
set v to lst's item i
set lst's item i to ""
set h to i - 2
set o to h
repeat
try
if ((lst's item o) [OPT-,] v and (lst's item (o + 1))
[NO-BREAK][OPT-.] v) then exit repeat
set h to (h + 1) div 2
if v < (lst's item o) then
set o to o - h
else
set o to o + h
end if
on error
set o to 1
end try
end repeat
set lst to ((lst's items 1 thru o) & v & (lst's items (o +
[NO-BREAK]1) thru -1))'s numbers
end if
end repeat
return lst's rest
end SortedNumbers


set lst to {140, 780, 75, 32, 564, 828, 111, 265, 402, 920, 794, 743,
[NO-BREAK]37, 176, 777, 302, 561, 747, 965, 159, 738, 226, 666, 599,
[NO-BREAK]147, 935, 881, 323, 480, 642, 753, 77, 747, 705, 537, 112,
[NO-BREAK]556, 709, 781, 565, 481, 376, 774, 952, 242, 97, 282, 451,
[NO-BREAK]49, 226, 157, 818, 466, 719, 788, 963, 774, 903, 305, 909,
[NO-BREAK]49, 794, 280, 418, 935, 533, 566, 442, 28, 832, 297, 689,
[NO-BREAK]269, 649, 432, 885, 183, 707, 19, 857, 848, 719, 859, 756,
[NO-BREAK]361, 469, 134, 659, 539, 704, 358, 231, 99, 643, 144, 997,
[NO-BREAK]895, 855, 977, 236, 307, 902, 571, 702, 443, 221, 778, 932,
[NO-BREAK]159, 993, 964, 624, 139, 618, 697, 157, 108, 388, 799, 121,
[NO-BREAK]644, 283, 324, 451, 921, 719, 917, 590, 555, 242, 361, 181,
[NO-BREAK]487, 205, 243, 189, 468, 49, 879, 433, 445, 945, 772, 770,
[NO-BREAK]256, 494, 838, 240, 981, 131, 617, 194, 594, 937, 43, 155,
[NO-BREAK]252, 458, 532, 936, 509, 848, 483, 847, 607, 989, 292, 86,
[NO-BREAK]98, 483, 725, 874, 178, 612, 835, 887, 903, 773, 785, 320,
[NO-BREAK]759, 419, 260, 307, 256, 89, 108, 526, 750, 640, 451, 12,
[NO-BREAK]596, 582, 911, 63, 59, 98, 669, 130}

SortedNumbers(lst)

======================================================================
[formatted using ScriptToEmail - http://www.?????]


  • Follow-Ups:
    • Toggle menu bar with Akua?
      • From: "Joseph A. Weaks" <email@hidden>
  • Prev by Date: Re: AppleScript Enigma
  • Next by Date: Word to pdf Batch conversion
  • Previous by thread: Re: Changing screen resolution
  • Next by thread: Toggle menu bar with Akua?
  • Index(es):
    • Date
    • Thread