Sorting algorithms/Insertion sort: Difference between revisions

→‎{{header|C++}}: same algorithm, better style
(Added BBC Basic and Cobol version of the insertion sort.)
(→‎{{header|C++}}: same algorithm, better style)
Line 232:
 
=={{header|C++}}==
FasterUses thanbinary the basic algorithmsearch becausevia std::lower_bound() findsto find the insertion position in logarithmic time., Insertionthen itself,performs performedthe insertion withvia std::rotate(), is stillin linear time.
 
<lang cpp>#include <algorithm>
#include <vector>
 
template<typename Iter>
void Isort(std::vector<int>& v)
void insertion_sort(Iter beg, Iter end)
{
for (std::vector<int>::iteratorIter i =v.begin() beg; i !=v. end(); ++i)
std::rotate(std::lower_bound(v.begin()beg, i, *i), i, i+1);
}</lang>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
Anonymous user