Jump to content

Algorithm Implementation/Sorting/Binary Tree Sort

From Wikibooks, open books for an open world
#include<set> // for multiset#include<algorithm> // for copytemplate<typenameIterator>voidbinary_tree_sort(Iteratorbegin,Iteratorend){// C++'s multiset class is a self-balancing binary search tree that allows duplicates// Add each element in input range to the treestd::multiset<typenamestd::iterator_traits<Iterator>::value_type>tree(begin,end);// Read elements in ascending order by simply traversing the tree.std::copy(tree.begin(),tree.end(),begin);}


close