# sort array of array

Discussion in 'C Programming' started by a, Nov 22, 2007.

1. ### aGuest

Dear all,

I have found quick sort codes and modified them to sort an array of
structure. Because I have many such rows to be sort, the input is indeed
array of "array of structure".

I have been confused with the *, [], **, &, and so. Could anybody help me
about what should be changed in order to get the sorting done?

====================================
In abc.h

struct tagged_array {
/*
int oldtag[SIZE];
int newtag[SIZE];
float value[SIZE];
*/
int oldtag;
int newtag;
float value;
};

void qs_struct(struct tagged_array items[], int, int);
void quick_struct(struct tagged_array items[], int);

====================================
In sort.c:

void qs_struct(struct tagged_array items[], int left, int right)
{

register int i, j;
float x;
struct tagged_array temp;

i = left; j = right;
x = items[(left+right)/2].value;

do {
while( (items.value < x) && (i < right)) i++;
while( (items[j].value > x) && (j > left)) j--;
if(i <= j) {
temp = items;
items = items[j];
items[j] = temp;
i++; j--;
}
} while(i <= j);

if(left < j) qs_struct(items, left, j);
if(i < right) qs_struct(items, i, right);
}

void quick_struct(struct tagged_array items[], int count)
{
qs_struct(items,0,count-1);
}
====================================

In main.c:

struct tagged_array dist[SIZE][SIZE];

quick_struct(dist, SIZE);
//quick_struct(dist[SIZE], SIZE);

====================================

a, Nov 22, 2007