Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

hpsort.c

Go to the documentation of this file.
00001 void hpsort(unsigned long n, float ra[])
00002 {
00003         unsigned long i,ir,j,l;
00004         float rra;
00005 
00006         if (n < 2) return;
00007         l=(n >> 1)+1;
00008         ir=n;
00009         for (;;) {
00010                 if (l > 1) {
00011                         rra=ra[--l];
00012                 } else {
00013                         rra=ra[ir];
00014                         ra[ir]=ra[1];
00015                         if (--ir == 1) {
00016                                 ra[1]=rra;
00017                                 break;
00018                         }
00019                 }
00020                 i=l;
00021                 j=l+l;
00022                 while (j <= ir) {
00023                         if (j < ir && ra[j] < ra[j+1]) j++;
00024                         if (rra < ra[j]) {
00025                                 ra[i]=ra[j];
00026                                 i=j;
00027                                 j <<= 1;
00028                         } else j=ir+1;
00029                 }
00030                 ra[i]=rra;
00031         }
00032 }

Generated at Sun Feb 24 09:57:04 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001