- 1、本文档共42页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
各种排序算法(国外英语资料)
各种排序算法(国外英语资料)
The various internal sorting sorting methods: bubble sort, quick sort, simple selection sort, binary insertion sort, Hill sort, heap sort, merge sort (non recursive algorithm), radix sort
(1) bubble sort
#includestdio.h
#includemalloc.h
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
Typedef struct
{
Int *elem;
Int length;
Int listsize;
}SqList;
Int InitList_Sq (SqList L)
{
L.elem= (ElemType*) malloc (LIST_INIT_SIZE*sizeof (ElemType));
If (... L.elem) return ERROR;
L.length=0;
L.listsize=LIST_INIT_SIZE;
Return OK;
}
Int Load_Sq (SqList L)
{
Int i;
If (L.length==0) printf (The, List, is, empty, \n);
Else
{
Printf (The List / / is:);
For (i=0; iL.length; i++)
Printf (%d, L.elem[i]);
Printf (\n);
}
Return OK;
}
Int, main ()
{
SqList L;
Int, I, J, t, f=0;
InitList_Sq (L);
Scanf (%d, L.length);
For (i=0; iL.length; i++)
{
Scanf (%d, L.elem[i]);
}
For (i=L.length-1; i=0; i--)
{
For (j=0; ji; j++)
{
If (L.elem[j]L.elem[j+1])
{
T=L.elem[j];
L.elem[j]=L.elem[j+1];
L.elem[j+1]=t;
F=1;
}
}
If (f==1) {Load_Sq (L); f=0;}
}
Load_Sq (L);
}
(2) quick sort
#includestdio.h
#includemalloc.h
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
Typedef struct
{
Int *elem;
Int length;
Int listsize;
}SqList;
Int InitList_Sq (SqList L)
{
L.elem= (ElemType*) malloc (LIST_INIT_SIZE*sizeof (ElemType));
If (... L.elem) return ERROR;
L.length=0;
L.listsize=LIST_INIT_SIZE;
Return OK;
}
Int Load_Sq (SqList L)
{
Int i;
If (L.length==0) printf (The, List, is, empty, \n);
Else
{
Printf (The List / / is:);
For (i=1; i=L.length; i++)
Printf (%d, L.elem[i]);
Printf (\n);
}
Return OK;
}
Int Partition (SqList, L, int, low, int, high)
{
Int key;
L.elem[0]=L.elem[low];
Key=L.elem[low];
While (lowhigh)
{
While (lowhighL.elem[high]=key) --high;
L.elem[low]=L.elem[high];
While (lowhighL.elem[low]=key) ++low;
L.elem[high]=L.elem[low];
}
L.elem[low]=L.elem[0];
Load_Sq (L);
Return low;
}
Void QSo
您可能关注的文档
- 分销模式的比较与选择(国外英语资料).doc
- 分而治之算法---快速排序(国外英语资料).doc
- 刍探我国合并会计报表的不足及改进(国外英语资料).doc
- 刍议体育学生班级的自主化管理(国外英语资料).doc
- 刘备的谋略(国外英语资料).doc
- 分析题(公共行政学)(国外英语资料).doc
- 刘永好:学会细胞裂变企业式全球化(国外英语资料).doc
- 刘立模拟题(国外英语资料).doc
- 刚性裁员 柔性管理(国外英语资料).doc
- 创世2 造物主2 攻略(国外英语资料).doc
- 新高考生物二轮复习讲练测第6讲 遗传的分子基础(检测) (原卷版).docx
- 新高考生物二轮复习讲练测第12讲 生物与环境(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第3讲 酶和ATP(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第9讲 神经调节与体液调节(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第11讲 植物生命活动的调节(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第8讲 生物的变异、育种与进化(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第5讲 细胞的分裂、分化、衰老和死亡(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第5讲 细胞的分裂、分化、衰老和死亡(检测)(原卷版).docx
- 新高考生物二轮复习讲练测第12讲 生物与环境(讲练)(原卷版).docx
- 新高考生物二轮复习讲练测第11讲 植物生命活动的调节(检测)(原卷版).docx
文档评论(0)