/***************************************************************************1* Copyright (C) 2007 by Sindre Aam�s *2* [email protected] *3* *4* This program is free software; you can redistribute it and/or modify *5* it under the terms of the GNU General Public License version 2 as *6* published by the Free Software Foundation. *7* *8* This program is distributed in the hope that it will be useful, *9* but WITHOUT ANY WARRANTY; without even the implied warranty of *10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *11* GNU General Public License version 2 for more details. *12* *13* You should have received a copy of the GNU General Public License *14* version 2 along with this program; if not, write to the *15* Free Software Foundation, Inc., *16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *17***************************************************************************/1819#ifndef INSERTION_SORT_H20#define INSERTION_SORT_H2122#include <functional>2324template<typename T, class Less>25void insertionSort(T *const start, T *const end, Less less) {26if (start >= end)27return;2829T *a = start;3031while (++a < end) {32const T e = *a;3334T *b = a;3536while (b != start && less(e, *(b - 1))) {37*b = *(b - 1);38b = b - 1;39}4041*b = e;42}43}4445template<typename T>46inline void insertionSort(T *const start, T *const end) {47insertionSort(start, end, std::less<T>());48}4950#endif /*INSERTION_SORT_H*/515253