Re: Sorting with Akua Sweets
Re: Sorting with Akua Sweets
- Subject: Re: Sorting with Akua Sweets
- From: John W Baxter <email@hidden>
- Date: Thu, 8 Nov 2001 14:21:26 -0800
At 7:30 -0600 11/6/2001, garrett wrote:
>
I want to be able to sort a variable but the variable I am using is a list
>
that has many sublists. What I want to do is sort the variable based on one
>
of the sublists. The trick is everything has to sort, not just the one list
>
inside.
>
>
EG: lets say the VAR X has FirstName, LastName, Company lists in it.
>
>
If I want to sort on the FIRSTNAME, LastName and Company have to switch
>
based on the new order of Firstname as well otherwise the whole things is
>
screwed up.
>
>
Any ideas?
The basic process (I'm not going to provide code, but some will probably
show up) is to sort something else.
Things are *much* easier if all the sublists are the same length...if there
is a chance that they aren't, you probably want to pad the short ones with
sentinals of some kind so all are the same. The list you describe should
have been built that way.
Now, make a list containing the integers 1 through the number of items in
the sublists.
Now, sort that list of numbers, using a comparison procedure which looks at
the contents of the FirstName list item determined by the item numbers in
your new list.
You should wind up with the new list having its numbers in an odd-looking
order...the first item in the "sorted" list is reached by asking for item 1
of your index list, and using that as item number in the main list, and so
on. If you need the big list permanently re-sorted, you'll need to copy
it...if you just need to be able to access it sequentially by FirstName,
you just walk through the index list accessing each item in the main list.
(That last comment is a hint that you can, if you like, effectively have
the list sorted in multiple ways at once: FirstName, LastName, Company,
and even "lastname, first name" if you want.)
The above is not the only way to do the job.
--John
--
John Baxter email@hidden Port Ludlow, WA, USA