add numerical recipes library
This commit is contained in:
29
lib/nr/k_and_r/recipes/hpsel.c
Normal file
29
lib/nr/k_and_r/recipes/hpsel.c
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
void hpsel(m,n,arr,heap)
|
||||
float arr[],heap[];
|
||||
unsigned long m,n;
|
||||
{
|
||||
void sort();
|
||||
void nrerror();
|
||||
unsigned long i,j,k;
|
||||
float swap;
|
||||
|
||||
if (m > n/2 || m < 1) nrerror("probable misuse of hpsel");
|
||||
for (i=1;i<=m;i++) heap[i]=arr[i];
|
||||
sort(m,heap);
|
||||
for (i=m+1;i<=n;i++) {
|
||||
if (arr[i] > heap[1]) {
|
||||
heap[1]=arr[i];
|
||||
for (j=1;;) {
|
||||
k=j << 1;
|
||||
if (k > m) break;
|
||||
if (k != m && heap[k] > heap[k+1]) k++;
|
||||
if (heap[j] <= heap[k]) break;
|
||||
swap=heap[k];
|
||||
heap[k]=heap[j];
|
||||
heap[j]=swap;
|
||||
j=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user