Re: Newbie problem with lists
Re: Newbie problem with lists
- Subject: Re: Newbie problem with lists
- From: email@hidden (Michael Sullivan)
- Date: Thu, 6 Jun 2002 13:30:27 -0400
- Organization: Society for the Incurably Pompous
>
You could either write a routine that does a bubble sort, going along the
>
list looking to see if item n>item (n+1). If true, set a flag. Repeat this
>
loop until the flag doesn't get set.
or if speed is an issue (the lists routinely get longer than 20 or so
items), you could use Arthur's InsertionSort or Serge's QuickSort
applemods.
Another option if you are always starting with sorted sublists is to
write a concatenator that uses that information to make an O(n) routine
to end up with a sorted list:
on concatsortedlists(list1, list2)
script o
property l : list1
property m : list2
property n : {}
end script
set {i, iMax} to {1, count of o's l}
set {j, jMax} to {1, count of o's m}
repeat while (i <= iMax) and (j <= jMax)
set a to item i of o's l
set b to item j of o's m
if a > b then
set end of o's n to b
set j to j + 1
else
set end of o's n to a
set i to i + 1
end if
end repeat
if i > iMax then
set o's n to o's n & items j thru jMax of o's m
else if j > jMax then
set o's n to o's n & items i thru iMax of o's l
end if
return o's n
end concatsortedlists
Michael
--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.