Anonymous user
Sorting algorithms/Insertion sort: Difference between revisions
m
some comments
(Added the implementation for Dart. This was translated from the Java version of the algorithm) |
m (some comments) |
||
Line 1,146:
#include <iterator>
// std::rotate is used to shift the sub-region
// if the predicate p is true
template <typename RandomAccessIterator, typename Predicate>
void insertion_sort(RandomAccessIterator begin, RandomAccessIterator end,
Line 1,154 ⟶ 1,156:
}
// calls with default Predicate std::less (sort ascending)
template <typename RandomAccessIterator>
void insertion_sort(RandomAccessIterator begin, RandomAccessIterator end) {
insertion_sort(begin, end,
▲ typename std::iterator_traits<RandomAccessIterator>::value_type>());
}
int main() {
int a[] = { 100, 2, 56, 200, -52, 3, 99, 33, 177, -199 };
insertion_sort(std::begin(a), std::end(a));
// 'iterates' numbers to std::cout
// converts ints to strings for output to screen
copy(std::begin(a), std::end(a), std::ostream_iterator<int>(std::cout, " "));
}</lang>
{{out}}
|