C语言排序.docVIP

  • 8
  • 0
  • 约1.07万字
  • 约 18页
  • 2018-05-28 发布于河南
  • 举报
C语言排序

C语言排序 这是c++的插入排序源程序 其他自己看吧!! # include iostream.h # include conio.h # define MAXSIZE 20 # define MAX_LENGTH 100 typedef int RedType; typedef struct { RedType r[MAXSIZE+1]; int length; }SqList; void InsertSort(SqList L) { int i,j; for(i=2;i =L.length;++i) if(L.r[i] L.r[i-1]) { L.r[0]=L.r[i]; for(j=i-1;L.r[0] L.r[j];--j) L.r[j+1]=L.r[j]; L.r[j+1]=L.r[0]; } } void main() { int i; SqList L; cout endl endl InsertSort.cpp ; cout endl ============== ; cout endl Please input the length of SqList (eg,5): endl endl; cin L.length; for(i=1;i =L.length;++i) { cout Please input the i th integer (eg,58): ; cin L.r[i]; } cout endl The disordered : ; for(i=1;i =L.length;i++) cout L.r[i] ; InsertSort(L); cout endl The ordered : ; for(i=1;i =L.length;i++) cout L.r[i] ; cout endl endl ...OK!... ; getch(); 对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 精华推荐:各位前辈,为什么很多人说真正的高手是C高手而非C++的呢 sylmoon (单独的狼) 等 级: #6楼 得分:15回复于:2002-06-19 21:02:37先来看看最基本的数组排序——冒泡排序。比如我们有一个数组为:2,57,29,89, 42,34,16,1。通过冒泡——大的沉下去,小的浮上来的原理,分别比较相邻的值, 大的往后排。如果相邻的两个值是升序排列的,就保持原样,如果是降序排列的,就 交换它们的值: start : a[0]2, a[1]57, a[2]29, a[3]89, a[4]42, a[5]34, a[6]16,a[7]1 1 times:2, 29, 57, 42, 34, 16, 1, 89 2 times: 2, 29, 42, 34, 16, 1, 57, 89 3 times: 2, 29, 34, 16, 1, 42, 57, 89 4 times: 2, 29, 16, 1, 34, 42, 57, 89 5 times: 2, 16, 1, 29, 34, 42, 57, 89 6 times: 2, 1, 16, 29, 34, 42, 57, 89 7 times: 1, 2, 16, 29, 34, 42, 57, 89 我们可以用两个循环来控制排序,一个控制趟数

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档