39int keys [] = { 36, 32, 4, 12, 52, 59, 2, 2, 26, 1 };
48# define LLINK(i, n) (2*i)
49# define RLINK(i, n) (2*i + 1)
77int main(
int argc,
char* argv[])
96 cerr <<
"Error: n must be a positive integer." << endl;
109 unsigned int i,
value;
111 for (i = 0; i < n; i++)
113 value = 1 + (int) (100.0*rand()/(RAND_MAX+1.0));
115 cout <<
value <<
" ";
133 for (i = 1; i <= heap.
size(); i++)
134 cout << heap[i] <<
" ";
138 for (i = 0; i < n; i++)
141 cout <<
value <<
" ";
148 int * array1 =
new int [n];
150 int * array2 =
new int [n];
152 for (
int i = 0; i < n; i++)
154 int value = 1 + (int) (100.0*rand()/(RAND_MAX+1.0));
155 array1[i] = array2[i] =
value;
159 for (
int i = 0; i < n; i++)
160 cout << array1[i] <<
" ";
168 for (
int i = 0; i < n; i++)
169 cout << array2[i] <<
" ";
size_t size_t int32_t value
Fixed-capacity binary heap backed by a raw array.
T & insert(const T &key)
Insert an element into the heap.
T getMin()
Remove the smallest element in the heap and return a copy of its value.
constexpr size_t size() const noexcept
Return the number of elements currently stored.
Main namespace for Aleph-w library functions.
constexpr void faster_heapsort(T *array, const size_t n, const Compare &cmp=Compare())
Optimized version of heapsort.
constexpr void heapsort(T *array, const size_t n, const Compare &cmp=Compare())
Sort an array using the heapsort algorithm.
Fixed-capacity binary heap and heapsort algorithms.