#include <stdio.h>
struct point
{
int a;
int b;
};
struct point a[] = {{3,56}, {6,1}, {3, 57}, {100, 2}, {0, 9}};
int sort(void *start, int n, int len, int (*compare)(void*, void *))
{
int i, j, max, k;
char *p1, *p2;
for(i = 0; i <= n-2; i++)
{
max = i;
for(j = i+1; j <= n-1; j++)
{
if(compare(start + max * len, start + j * len) < 0)
{
max = j;
}
}
if(max == i)
continue;
p1 = start + i * len;
p2 = start + max * len;
for(k = 0; k < len; k++)
{
*p1 = *p1 ^ *p2;
*p2 = *p1 ^ *p2;
*p1 = *p1 ^ *p2;
p1++;
p2++;
}
}
}
int compare(void *p1, void *p2)
{
struct point a = *(struct point*)p1, b = *(struct point*)p2;
if(a.a > b.a || (a.a == b.a && a.b > b.b))
return 1;
else if(a.a == b.a && a.b == b.b)
return 0;
else
return -1;
}
/*
int compare(void *p1, void *p2)
{
int a = *(int*)p1, b = *(int*)p2;
if(a > b)
return 1;
else if(a == b)
return 0;
else
return -1;
}
*/
int main()
{
sort(a, 5, 8, compare);
int i;
for(i = 0; i < 5; i++)
printf("%d %d\n", a[i].a, a[i].b);
}
|