C++排序类模板, 排序类

本文介绍了作者在C++中创建排序类模板的实践过程,包括希尔排序、快速排序、归并排序、选择排序、冒泡排序、堆排序和插入排序的实现,并提及了二分查找的添加。代码经过了初步测试。
摘要由CSDN通过智能技术生成

我的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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值