Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting 2 variables: one ascending, one descending
#1
In the Newbie Help section Licentia recently posted a problem regarding sorting in descending order. This reminded me of similar problem about sorting 2 different keys where one must be ascending and the other descending.

If you're not using a Quick sort, you could do two sorts on the data, one for each key. But that's kinda like cheating.

So here's the challenge.
GIVEN:
* Data records containing a LAST NAME string, left justified, in positions 1 to 10 of each record.
* Also in each record we have an AGE string, right justified, in positions 11 to 12.
* There should be at least 10 records, and at least 2 or more should have the same NAME with different AGES.

PROBLEM:
* Write any sort routine you like to sort, in one pass, the NAME fields in ascending order, and to also sort the AGE fields in descending order.

Example: If there are 3 SMITH records with ages 10, 15 and 20, then the sorted output for these should show:
SMITH 20
SMITH 15
SMITH 10

Get it?

HINT: The solution is not in having a tricky sort routine, but in setting up your sort key properly.
*****
Reply


Messages In This Thread
Sorting 2 variables: one ascending, one descending - by Moneo - 11-07-2004, 06:44 AM
My Submission - by Meg - 11-08-2004, 10:26 PM
Hey!.. - by ToohTooh - 11-08-2004, 11:16 PM
Now this is serious. - by ToohTooh - 11-10-2004, 07:13 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)