MCPcopy Create free account
hub / github.com/MyGUI/mygui / insertion_sort

Function insertion_sort

Tools/EditorFramework/pugixml.cpp:6151–6180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6149
6150template<typename I, typename Pred, typename T>
6151void insertion_sort(I begin, I end, const Pred& pred, T*)
6152{
6153 assert(begin != end);
6154
6155 for (I it = begin + 1; it != end; ++it)
6156 {
6157 T val = *it;
6158
6159 if (pred(val, *begin))
6160 {
6161 // move to front
6162 copy_backwards(begin, it, it + 1);
6163 *begin = val;
6164 }
6165 else
6166 {
6167 I hole = it;
6168
6169 // move hole backwards
6170 while (pred(val, *(hole - 1)))
6171 {
6172 *hole = *(hole - 1);
6173 hole--;
6174 }
6175
6176 // fill hole with element
6177 *hole = val;
6178 }
6179 }
6180}
6181
6182// std variant for elements with ==
6183template<typename I, typename Pred>

Callers 1

sortFunction · 0.70

Calls 1

copy_backwardsFunction · 0.70

Tested by

no test coverage detected