- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
排序的模板实现(Template implementation of sorting)
#包含iostream
#包括数学。”
#包括时间。”
#包括程序。”
#包括向量
使用名称空间;
数组长度
常量= 10;
/复数类的定义
类的复杂{
公共:
双m_x;/ /房
双m_y;/ /图像
双comsqrt() {
返回sqrt(m_x * m_x + m_y * m_y);
}
无效(){
m_x = rand() % 10;
m_y = rand() % 10;
}
布尔运算符(复杂 B)
{
双T = comsqrt();
双S = B comsqrt();
如果(t)
返回true;
其他的
返回false;
}
};
/类的基类定义
模板
类csortbase {
公共:
typedef void(csortbase::* pswap)(T,T );
typedef int(csortbase::* pcompare)(T,T );
csortbase() {
}
CSortBase(T P、T×Q){
iterator_begin =(void *)P;
iterator_end =(void *)q;
}
虚拟~ csortbase() {
}
//由派生类重写的虚函数
basesort() { void
sort();
}
初始化(t,p,t,q)
{
iterator_begin = P;
iterator_end = Q;
}
无效output()
{
int = i 0;
T * pbegin = iterator_begin;
而(pbegin iterator_end)
{
cout +我”:“ * pbegin endl;
pbegin + +;
}
}
受保护的:
T * iterator_begin;
T * iterator_end;
虚交换(t,a,t和b){
T = a;
甲=乙;
B = T;
}
int比较(t,a,t和b){
返回A?1:0;
}
指向复杂动态数组的指针
私人:
虚sort() { }
};
模板
csortbubble类:公共csortbase T {
公共:
csortbubble() {
}
~ csortbubble() {
}
私人:
实现冒泡排序
无效sort();
无效的冒泡排序算法(T * iter_begin,T * iter_end,pswap互换,pcompare比较);
指向复杂动态数组的指针
};
实现冒泡排序
模板
无效csortbubble T::sort()
{
BubbleSort((T)iterator_begin,(T *)iterator_end,(pswap)交换,(pcompare)比较);
}
模板
无效csortbubble T::BubbleSort(T * iter_begin,T * iter_end,pswap互换,pcompare比较)
{
T P = iter_end;
为(T * IP = iter_begin;IP iter_end;IP + +)
{
为(T * JP = iter_begin + 1;JP 小彭;JP + +)
{
如果(1 = = csortbase T::比较(*(管),* JP))
{
csortbase T::互换(*(管),* JP);
}
}
小彭--;
}
}
模板
csortselect类:公共csortbase T {
公共:
csortselect() {
}
~ csortselect() {
}
私人:
//选择排序实现
无效sort();
虚空SelectSort(T * iter_begin,T * iter_end,pswap互换,pcompare比较);
指向复杂动态数组的指针
};
模板
无效csortselect T::sort()
{
SelectSort((T)iterator_begin,(T *)iterator_end,(pswap)交换,(pcompare)比较);
}
模板
无效csortselect T::SelectSort(T * iter_begin,T * iter_end,pswap互换,pcompare比较)
{
为(T * IP = iter_begin;IP iter_end;IP + +)
为(T * JP = iter_end-1;JP IP;JP --)
{
如果(1 = =(csortbase T::比较)(*(管),* JP))
csortbase T::互换(*(管),* JP);
}
}
模板
csortinsert类:公共csortbase T {
公共:
csortinsert() {
您可能关注的文档
- 《现代文学三十年》鲁迅复习笔记 很好的东西(Thirty years of modern literature, Lu Xun reviewed notes very well).doc
- 《仰望星空与脚踏实地》(Starry sky and down to earth).doc
- 《因数中间或末尾有零的乘法》案例分析(Case analysis of multiplication of zero in the middle of a factor or at the end).doc
- 《游戏的封包、资源和提取器》简介(Brief introduction of game, and packet resource extractor).doc
- 《圆的周长》导学案(The guide to the circumference of a circle).doc
- 《月光下的凤尾竹》创作背景及演奏技巧&方法讲解(In the background of Moonlight creation and performance skills & methods of explanation).doc
- 《圆柱的表面积》教学设计(Teaching design of surface area of cylinder).doc
- 《战火兄弟连之地狱公路》游戏流程全攻略(Fire brothers even hell highway game process Raiders).doc
- 《哲学与人生》期末试卷及答案(Final papers and answers to Philosophy and life).doc
- 《张惠妹2010阿密特世界巡回演唱会》(Sherry 2010 live world tour).doc
原创力文档


文档评论(0)