# include "imclean.h"

void sort_stars (Stars *X, int N) {

  int l,j,ir,i;
  Stars tX;
  
  if (N < 1) return;
  l = N >> 1;
  ir = N - 1;
  for (;;) {
    if (l > 0) {
      l--;
      tX = X[l];
    }
    else {
      tX = X[ir];
      X[ir] = X[0];
      if (--ir == 0) {
	X[0] = tX;
	return;
      }
    }
    i = l;
    j = (l << 1) + 1;
    while (j <= ir) {
      if (j < ir && X[j].X < X[j+1].X) j++;
      if (tX.X < X[j].X) {
	X[i] = X[j];
	j += (i=j) + 1;
      }
      else j = ir + 1;
    }
    X[i] = tX;
  }
}
