排序算法C++实现的通用头文件
#pragma once
#include <vector>
#include <string>
template <typename Container>
void printList(Container& list)
{
for (auto &x : list) {
std::cout << x << " ";
}
std::cout << std::endl;
}
template <typename Iterator>
void printList(const Iterator& begin, const Iterator& end)
{
for (Iterator i = begin; i != end; i++) {
std::cout << *i << " ";
}
std::cout << std::endl;
}
template <class T> struct greater_
{
bool operator () (const T& x, const T& y) const { return x > y; }
typedef T first_argument_type;
typedef T secont_argument_type;
typedef bool result_type;
};
template <class T> struct less_
{
bool operator () (const T& x, const T& y) const { return x < y; }
typedef T first_argument_type;
typedef T secont_argument_type;
typedef bool result_type;
};
template <typename Iterator>
void insertionSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void insertionSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator>
void shellSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void shellSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator>
void mergeSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void mergeSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator, typename Comparator>
void merge(const Iterator& begin, const Iterator& mid, const Iterator& end, Comparator lessThan);
template <typename Iterator>
void quickSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void quickSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator, typename Comparator>
Iterator swapLeftRight(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator>
void bucketSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void bucketSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
void radixSort(int arr[], int length);
template <typename T>
void heapSort(const T& arr);
template <typename Iterator>
void heapSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void heapSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator>
void bubbleSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void bubbleSort(const Iterator& begin, const Iterator& end, Comparator lessThan);
template <typename Iterator>
void selectionSort(const Iterator& begin, const Iterator& end);
template <typename Iterator, typename Comparator>
void selectionSort(const Iterator& begin, const Iterator& end, Comparator lessThan);