A89: TIBasic: Sorting Lists - Help Needed ???


[Prev][Next][Index][Thread]

A89: TIBasic: Sorting Lists - Help Needed ???



I have a problem determining how lists are 
sorted (for duplicate values).  I have attached
an example program that demonstrates the problem.

I have 6 lists that contain data.  I want to sort
the lists like: 

SortD a, e, b, c, d, nm (sort based on ListA)
SortD b, e, a, c, d, nm (sort based on ListB) 
SortD c, e, a, b, d, nm (sort based on ListC)
SortD d, e, a, b, c, nm (sort based on ListD)

The basic sorting works, but I am having trouble
sorting duplicates based on a second key.

I want the duplicate entries to be sorted by a 
second key (ListE).  The problem is is that I am 
not able to figure out a way to do this.  I have 
tried several ways but it seems kind of 
UNPREDICTABLE how this sort handles duplicate 
list items.

At first I thought that: SortD a, e, b, c, d, nm
might work.  But the other lists do not effect 
sort order, in this single sort.

So, then I decided to sort twice with:

SortD e, a, b, c, d, nm  (sorts by ListE first)
SortD c, e, b, c, d, nm  (sorts on ListC),

thinking that maybe if I got the ListE sort 
order first that the duplicates would be sorted 
correctly with the 2nd sort.  But that did not 
work either.

However, the first sorting DOES affect the 
second sort, but in an unpredictible manner. 
Depending on the first sort, the second is 
affected.

Examples (Focus on Name3 and Name4 orders):

1) FIRST: SortD c, e, a, b, d, nm (Name3 should 
appear before Name4 because ListE value for 
Name3 is greater than ListE value for Name4; but 
it doesn't).

2) NOW: SortD e, a, b, c, d, nm first followed 
by SortD c, a, b, c, d, nm.  No change in order 
of Name3 and Name4.

3) BUT: SortD d, a, b, c, e, nm first followed 
by SortD c, a, b, c, d, nm.  This time the sort 
order is Name4 followed by Name3 (correct order; 
but why?).

So, what is going on here (why does the first 
sort, in 2 and 3, affect the 2nd sort; and how 
is it predictable)?  How does the sorting handle 
duplicate values?  How can one sort on a second 
key?

Original List Data (non-porportional font):

ListNM  ListA  ListB  ListC  ListD  ListE
-----------------------------------------
Name1   9.2    9.3    9.4    9.5    37.4
Name2   9.0    9.1    9.2    9.3    36.6
Name3   8.5    8.7    8.2    8.0    33.4
Name4   8.0    8.0    8.2    8.1    32.3
Name5   9.5    6.0    6.0    7.0    28.5
XXX     9.5    6.0    6.0    7.0    28.5
YYY     5.0    6.0    9.5    7.0    27.5
MMM     9.0    9.0    0.0    0.0    18.0
RRR     9.6    0.0    0.0    0.0     9.6
PPP     9.4    0.0    0.0    0.0     9.4
OOO     9.0    0.0    0.0    0.0     9.0
NNN     8.5    0.0    0.0    0.0     8.5
QQQ     8.0    0.0    0.0    0.0     8.0
TTT     5.0    0.0    0.0    0.0     0.0
(the rest of the list is 0.0)


--
-----------------------------------------------------------------
Discussion Group:        http://www.halcyon.com/ipscone/wwwboard/

Protect your constitutional rights. Your favorite one may be next!
-----------------------------------------------------------------
The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any another MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- File information -----------
     File:  SortTst.89g
     Date:  26 Jan 1999, 21:12
     Size:  3838 bytes.
     Type:  Unknown

SortTst.89g