资源描述:
《c语言实现简单排序(种方法)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include//冒泡排序voidbubleSort(intdata[],intn);//快速排序voidquickSort(intdata[],intlow,inthigh);intfindPos(intdata[],intlow,inthigh);//插入排序voidbInsertSort(intdata[],intn);//希尔排序voidshellSort(intdata[],intn);//选择排序voidselectSort(intdata[],intn);//堆排序voidheapSort(intdata[],intn);v
2、oidswap(intdata[],inti,intj);voidheapAdjust(intdata[],inti,intn);//归并排序voidmergeSort(intdata[],intfirst,intlast);voidmerge(intdata[],intlow,intmid,inthigh);//基数排序voidradixSort(intdata[],intn);intgetNumPos(intnum,intpos);intmain(){intdata[10]={43,65,4,23,6,98,2,65,7,79};inti;printf("原先数组:");for(i=0;i
3、<10;i++){printf("%d",data[i]);}printf("");/*printf("冒泡排序:");bubleSort(data,10);for(i=0;i<10;i++){printf("%d",data[i]);}printf("");printf("快速排序:");quickSort(data,0,9);for(i=0;i<10;i++){printf("%d",data[i]);}printf("");printf("插入排序:");bInsertSort(data,10);for(i=0;i<10;i++){printf("%d",data[i]);}
4、printf("");printf("希尔排序:");shellSort(data,10);for(i=0;i<10;i++){printf("%d",data[i]);}printf("");printf("选择排序:");selectSort(data,10);for(i=0;i<10;i++){printf("%d",data[i]);}printf("");intdata[11]={-1,43,65,4,23,6,98,2,65,7,79};inti;printf("原先数组:");intdata[11]={-1,43,65,4,23,6,98,2,65,7,79};for
5、(i=1;i<11;i++){printf("%d",data[i]);}printf("");printf("堆排序:");heapSort(data,10);for(i=1;i<11;i++){printf("%d",data[i]);}printf("");printf("归并排序:");mergeSort(data,0,9);for(i=0;i<10;i++){printf("%d",data[i]);}printf("");*/printf("基数排序:");radixSort(data,10);for(i=0;i<10;i++){printf("%d",data[i])
6、;}printf("");return0;}/*--------------------冒泡排序---------------------*/voidbubleSort(intdata[],intn){inti,j,temp;//两个for循环,每次取出一个元素跟数组的其他元素比较//将最大的元素排到最后。for(j=0;jdata[i+1]){temp=data[i];data[i]=data[i+1];data[i+1]=te
7、mp;}}}}/*--------------------快速排序---------------------*/intfindPos(intdata[],intlow,inthigh){//将大于t的元素赶到t的左边,大于t的元素赶到t的右边intt=data[low];while(low=t){high--;}data[low]