• 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: Newbie problem with lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie problem with lists


  • Subject: Re: Newbie problem with lists
  • From: Arthur J Knapp <email@hidden>
  • Date: Thu, 06 Jun 2002 16:03:09 -0400

> Subject: Re: Newbie problem with lists
> From: email@hidden (Michael Sullivan)
> Date: Thu, 6 Jun 2002 13:30:27 -0400

> 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)

Why, you're half way to a merge sort. ;-)


> script o
> property l : list1
> property m : list2
> property n : {}

You may notice that there is no real speed advantage to defining n
within the 'Serge' object. "set end of n" and "set end of o's n" are
roughly equivilent in speed, (in this case, anyway). It is only when
"items" are being accessed by index that faster access is occurs.

> 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


Good stuff. :)


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.apple.com/applescript/>
on error number -128
end try
}
_______________________________________________
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.

  • Prev by Date: hmmm... did I ask too many questions?
  • Next by Date: Re: hmmm... did I ask too many questions?
  • Previous by thread: Re: Newbie problem with lists
  • Next by thread: Is it possible to get owner name and use it to mount an volume
  • Index(es):
    • Date
    • Thread