Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

#include #include #include #include #include #include "TreapNode.h" #include "Treap.h" typedef std::vector::iterator Vit; void treap_sort (Vit begin, Vit end) { std::srand(42); // initialize rand Treap t; // insert elements into treap... for (Vit vit = begin; vit != end; ++vit) t.insert (*vit); assert (t.is_valid()); // ...and extract them in sorted orderr for (Vit vit = begin; vit != end; ++vit) *vit = t.remove_min(); } int main() { // input of number of values to be sorted int n; std::cin >> n; std::vector v(n); std::cout << "Sorting " << n << " integers...\n"; // create sequence: for (int i=0; i