// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <stdlib.h>

#include <iostream>

using namespace std;

struct mys {
   int a;
   int b;
};

int sorta(const void *s1,const void *s2)
{
   return (((mys *)s1)->a - ((mys *)s2)->a);
}

int sortb(const void *s1,const void *s2)
{
   return (((mys *)s1)->b - ((mys *)s2)->b);
}

int main()
{
   struct mys x[3];
   x[0].a=1;
   x[0].b=3;
   x[1].a=2;
   x[1].b=2;
   x[2].a=3;
   x[2].b=1;
   qsort(x,3,sizeof(mys),sorta);
   for(int i=0;i<3;i++) cout << x[i].a << " " << x[i].b << endl;
   qsort(x,3,sizeof(mys),sortb);
   for(int i=0;i<3;i++) cout << x[i].a << " " << x[i].b << endl;
}
