1 static void hyper_sort(int base,int number,void (*makesmaller)())
5 for (i=0;i<(number/2);i++)
6 makesmaller(base+i,base+i+((number+1)/2));
8 hyper_sort(base+number/2,(number+1)/2,makesmaller);
9 hyper_sort(base,number - (number+1)/2,makesmaller);
13 static void batchers_sort(int baseP,int N,void (*makesmaller)())
15 int p, initq, q, r, d, x;
17 for (p=1; (1<<(p+1))<=N+1; p++);
20 for (initq=p; p>0; p/=2)
29 makesmaller(baseP+x,baseP+x+d);
37 #define MAX_STEPS 10000
42 struct pair steps[MAX_STEPS];
46 void makesmaller(int n1,int n2)
55 int conflict(struct pair *p,int step)
59 if (step == steps[i].step &&
60 (steps[i].n1 == p->n1 ||
61 steps[i].n1 == p->n2 ||
62 steps[i].n2 == p->n1 ||
63 steps[i].n2 == p->n2))
77 if (steps[i].step>0 && !conflict(&steps[i],steps[i].step-1)) {
87 int comparison(struct pair *p1,struct pair *p2)
89 if (p1->step != p2->step) return(p1->step - p2->step);
90 if (p1->n1 != p2->n1) return(p1->n1 - p2->n1);
91 if (p1->n2 != p2->n2) return(p1->n2 - p2->n2);
100 if (steps[i].step != step) {
104 printf("%d: %d %d\n",steps[i].step,steps[i].n1,steps[i].n2);
106 printf("\n%d steps\n",step+1);
110 main(int argc,char *argv[])
112 batchers_sort(0,atoi(argv[1]),makesmaller);
116 qsort(&steps[0],N,sizeof(struct pair),comparison);