# include "gcompare.h"

void sort (data)
data_type data;
{
  int l,j,ir,i, N;
  value_type temp;

  N = data.Nvalues;
  if (N == 1)
    return;

  l = N >> 1;
  ir = N - 1;
  for (;;) {
    if (l > 0) {
      temp = data.values[--l];
    }
    else {
      temp = data.values[ir];
      data.values[ir] = data.values[0];
      if (--ir == 0) {
        data.values[0] = temp;
        return;
      }
    }
    i = l;
    j = (l << 1) + 1;
    while (j <= ir) {
      if (j < ir && data.values[j].X < data.values[j+1].X) ++j;
      if (temp.X < data.values[j].X) {
        data.values[i]=data.values[j];
        j += (i=j) + 1;
      }
      else j = ir + 1;
    }
    data.values[i] = temp;
  }
}

