我的C++一直比较水,平时都用C写程序,今天想写一个排序类模板,练习一下。
希尔排序,快速排序,归并排序,选择排序,冒泡排序,堆排序,插入排序
再添加一个二分法查找吧。
这些代码只经过了简单的测试。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
template <class Type>
class sort {
public:
sort(int (*cmp)(Type t1, Type t2));
~sort() {}
void adjust_heap(Type *root, int i, int size);
void create_heap(Type *root, int size);
void heap_sort(Type *root, int size);
void select_sort(Type *root, int size);
void shell_sort(Type *root, int size);
void quick_sort(Type *root, int l ,int r);
int partition(Type *root, int l, int r);
void merge_sort(Type *root, int l, int r);
void merge(Type *root, int l, int mid, int r);
void bubble_sort(Type *root, int size);
void insert_sort(Type *root, int size);
Type *binary_search(Type *root, int size, Type *s);
private:
in