#include "Sort.h"
#include <cassert>
using namespace Sort;
template<class T>
inline bool AbstractSort<T>::compare(uint index1, uint index2){
// we assert index2 is bigger than index1
// exp: return false if index1>index2 and sort is ascend.
assert(index1 < length && index2 < length);
assert(index2 > index1);
this->compare_times++;
if(this->is_ascend) return (this->src_list[index2] >= this->src_list[index1]);
else return (this->src_list[index2] <= this->src_list[index1]);
}
template<class T>
inline void AbstractSort<T>::swap(uint index1, uint index2){
assert(index1 < length && index2 < length);
this->swap_times++;
auto tmp = this->src_list[index1];
this->src_list[index1] = this->src_list[index2];
this->src_list[index2] = tmp;
}
template<class T>
inline void AbstractSort<T>::assign(uint start, uint len, T* data)
{
assert(start + len <= this->length);
this->assign_times += len;
for(uint i = 0; i < len; ++i)
this->src_list[start + i] = data[i];
}
template<class T>
std::ostream& AbstractSort<T>::display(std::ostream& out)const{
for(uint i = 0; i < this->length; ++i)
out << this->src_list[i] << " ";
return out << std::endl;
}
template<class T>
std::ostream& AbstractSort<T>::detail(std::ostream& out)const{
out << "Swap and compare times of this sort method are show below:" << std::endl;
out << "- The swap times: " << this->swap_times << std::endl;
out << "- The compare times: " << this->compare_times << std::endl;
out << "- The directly assign times: " << this->assign_times << std::endl;
return out;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Qt和C++的排序算法实现,优秀数据结构程序设计,新手必看! 基于Qt和C++的排序算法实现,优秀数据结构程序设计,新手必看! 基于Qt和C++的排序算法实现,优秀数据结构程序设计,新手必看! 基于Qt和C++的排序算法实现,优秀数据结构程序设计,新手必看! 基于Qt和C++的排序算法实现,优秀数据结构程序设计,新手必看! 基于Qt和C++的排序算法实现,优秀数据结构程序设计,新手必看!
资源推荐
资源详情
资源评论
收起资源包目录
SortMethod.zip (16个子文件)
SortMethod
HashString.h 532B
QuickSort.cpp 659B
MergeSort.cpp 1KB
Makefile 102B
ShellSort.cpp 1KB
result.md 1KB
PseudoShell.h 3KB
AbstractSort.cpp 2KB
main.cpp 92B
Header.h 178B
interact.py 1KB
InsertSort.cpp 457B
Sort.h 3KB
BubbleSort.cpp 437B
run.sh 45B
SelectionSort.cpp 515B
共 16 条
- 1
资源评论
振华OPPO
- 粉丝: 27w+
- 资源: 534
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功