Sorting multiple values at once. 
Author Message
 Sorting multiple values at once.

I was wondering if someone could help me with the following problem that
I have.

I must take in a 2-d array containing integer variables as my argument,
and I must sort the rows based on the values within the columns. The number of rows and
columns is not specified until the program begins to run.
This is part of a bigger project which requires the data to be pre-sorted, and without
this, I am unable to get going on the more important problem at hand. Any help is
appreciated.

Basically, I must use the standard qsort function which looks something like this on the
man page:

#include <stdio.h>
static int intcompare(i,j)
int *i, *j;
{
return(*i - *j);

Quote:
}

main()
{

int a[10];
int i;

a[0] = 9;
a[1] = 8;
a[2] = 7;
a[3] = 6;
a[4] = 5;
a[5] = 4;
a[6] = 3;
a[7] = 2;
a[8] = 1;
a[9] = 0;

qsort(a,10,sizeof(int),intcompare);

for (i=0; i<10; i++)
   printf(" %d",a[i]);
printf("\n");

Quote:
}

So, what I was wondering is if you could explain to me how I would alter this so that
the following data would be properly sorted:

INPUT
-----

3 4 3
4 7 3
3 4 3
5 2 5
4 8 2
4 7 2

OUTPUT
------

3 4 3
3 4 3
4 7 2
4 7 3
4 8 2
5 2 5

Your help is greatly appreciated,
Kyle :)



Wed, 26 Apr 2000 03:00:00 GMT  
 Sorting multiple values at once.

Make the comparison function compare the most significant element first.  If it
 is > or < return 1 or -1.  If equal compare the next most significant element.
  If it is > or < return 1 or -1.  When you have reached the last element, if
 it is > , = or < return 1, 0 or -1.

I'm at home, so I say anything I please.



Thu, 27 Apr 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Multiple things at once

2. Multiple strtok's at once

3. : Closing multiple dialog boxes at once

4. PlaySound - playing multiple sounds at once

5. : Closing multiple dialog boxes at once

6. Multiple views open at once with only one document

7. Sorting on double values.

8. Multiple key sort

9. SortedList sorted by value.

10. Sorting Array Error - left operand must be L-value

11. How To: Sort map by Value(second)

12. how to have multiple sorts in a STL list

 

 
Powered by phpBB® Forum Software