# include "lightcurve.h"

void sort_seq (seq, value, N) 
int *seq;
double *value;
int N;
{
  int l,j,ir,i;
  int temp;
  
  l = N >> 1;
  ir = N - 1;
  for (;;) {
    if (l > 0) {
      temp = seq[--l];
    }
    else {
      temp = seq[ir];
      seq[ir] = seq[0];
      if (--ir == 0) {
	seq[0] = temp;
	return;
      }
    }
    i = l;
    j = (l << 1) + 1;
    while (j <= ir) {
      if (j < ir && value[seq[j]] < value[seq[j+1]]) ++j;
      if (value[temp] < value[seq[j]]) {
	seq[i]=seq[j];
	j += (i=j) + 1;
      }
      else j = ir + 1;
    }
    seq[i] = temp;
  }
}


