-
Notifications
You must be signed in to change notification settings - Fork 4
/
heapsort.cc
38 lines (28 loc) · 652 Bytes
/
heapsort.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>
#include <iostream>
#include <unistd.h>
#include <lace/haystack.h>
#include "heap.h"
struct node {
int value;
node(int v) : value(v) { }
lite::heap_link<node> heap_link;
typedef lite::heap<node, &node::heap_link, typeof(node::value), &node::value> heap_t;
};
int
main(int, char*[]) {
lace::haystack h;
node::heap_t heap;
h.alignment_mask() = alignof(node) - 1;
while (std::cin) {
int i;
if ((std::cin >> i).good())
heap.inhume(new (h.allocate<node>()) node(i));
}
while (!heap.empty()) {
node* x = heap.exhume();
std::cout << x->value << std::endl;
}
return EXIT_SUCCESS;
}
//