17 #ifndef MERGE_SORT_INCLUDED
18 #define MERGE_SORT_INCLUDED
61 template<
typename Element_type,
typename Comp_func>
62 void insert_sort(Element_type **first, Element_type **last, Comp_func comp)
64 for (Element_type **high_water_mark= first+1;
65 high_water_mark < last;
68 for (Element_type **cur= high_water_mark; cur > first ; cur--)
70 if (comp(*(cur-1), *cur))
73 Element_type *tmp= *(cur-1);
99 template<
typename Element_type,
typename Comp_func>
100 void merge_sort(Element_type **first, Element_type **last, Comp_func comp)
102 const uint elements= last - first;
113 Element_type **middle= first + (elements)/2;
118 std::queue<Element_type *> merged;
120 Element_type **cur1= first;
121 Element_type **cur2= middle;
123 for (uint
i= 0;
i < elements;
i++)
125 DBUG_ASSERT (cur1 < middle || cur2 < last);
128 merged.push(*cur2++);
129 else if (cur2 == last)
130 merged.push(*cur1++);
131 else if (comp(*cur1, *cur2))
132 merged.push(*cur1++);
134 merged.push(*cur2++);
137 Element_type **result= first;
138 while (!merged.empty())
140 *result++= merged.front();