Functions | |
template<class I, class V> | |
void | CH_Tools::heapify (int i, int n, I &ind, const V &val) |
Heapify element i (in 0,...,n-1) in ind, so that afterwards val[ind[j]]>=max(val[ind[2*j+1]],val[ind[2*j+2]] for the subtree with root i. | |
template<class I, class V> | |
void | CH_Tools::build_heap (int n, I &ind, const V &val) |
Build a heap out of ind[0] to ind[n-1], so that val[ind[j]]>=max(val[ind[2*j+1]],val[ind[2*j+2]] for all j. | |
template<class I, class V> | |
void | CH_Tools::heapsort (int n, I &ind, const V &val) |
Sort ind[0]...ind[n-1] so that val[ind[i]]<=val[ind[j]] for 0<=i<j<n. |
For given
the routines sort the first n entries in the index array such that
val[ind[i]]<=val[ind[j]] for 0<=i<j<n
void CH_Tools::build_heap | ( | int | n, | |
I & | ind, | |||
const V & | val | |||
) | [inline] |
Build a heap out of ind[0] to ind[n-1], so that val[ind[j]]>=max(val[ind[2*j+1]],val[ind[2*j+2]] for all j.
n | index array goes from 0 .. n-1 | |
ind | index array into val, rearrangeable by swap(ind[j],ind[k]) | |
val | value array index by ind[j], comparable by "<" |
References CH_Tools::heapify().
Referenced by CH_Tools::heapsort().
void CH_Tools::heapify | ( | int | i, | |
int | n, | |||
I & | ind, | |||
const V & | val | |||
) | [inline] |
Heapify element i (in 0,...,n-1) in ind, so that afterwards val[ind[j]]>=max(val[ind[2*j+1]],val[ind[2*j+2]] for the subtree with root i.
i | index of element to be heapfied (indexing starts with 0) | |
n | index array goes from 0 .. n-1 | |
ind | index array into val, rearrangeable by swap(ind[j],ind[k]) | |
val | value array index by ind[j], comparable by "<" |
Referenced by CH_Tools::build_heap(), and CH_Tools::heapsort().
void CH_Tools::heapsort | ( | int | n, | |
I & | ind, | |||
const V & | val | |||
) | [inline] |
Sort ind[0]...ind[n-1] so that val[ind[i]]<=val[ind[j]] for 0<=i<j<n.
n | index array goes from 0 .. n-1 | |
ind | index array into val, rearrangeable by swap(ind[j],ind[k]) | |
val | value array index by ind[j], comparable by "<" |
References CH_Tools::build_heap(), and CH_Tools::heapify().