编写函数实现顺序查找,折半查找,直接选择法排序,冒泡法排序和直接插入法排序的代码,并进行测试验证.
//1。 冒泡排序#include /*************************************************************** BubbleSort:冒泡排序实现函数(从小到大 * * 参数:a[]:排序前的整型数组 ** n:数组元素数 ** 返回值:无 * *...全部
//1。
冒泡排序#include /*************************************************************** BubbleSort:冒泡排序实现函数(从小到大 * * 参数:a[]:排序前的整型数组 ** n:数组元素数 ** 返回值:无 * ***************************************************************/void BubbleSort(int a[],int n){ int temp=0; int i=0; int j=0; int k=0; int swap=0; int swapNum=0; for(i=0; ii; --j ) { if( a[j]则为从大到小排序 { temp=a[j-1]; a[j-1]=a[j]; a[j]=temp; swap=0; swapNum ; } for( k=0; k/*************************************************************** SelectSort:选择排序实现函数(从小到大排序 * * 参数:a[]:排序前的整型数组 ** n:数组元素数 ** 返回值:无 * ***************************************************************//*void SelectSort(int a[],int n){ int temp=0; int i=0; int j=0; int k=0; for( i=0; ia[j] ) //改为/*************************************************************** InsertSort:插入排序实现函数(从小到大排序) * * 参数:a[]:排序前的整型数组 ** n:数组元素个数 * * 返回值:无 ****************************************************************//*void InsertSort(int a[], int n){ int i=0; int j=0; int k=0; int temp=0; for( i=1; i=0 && tempa[j]为从大到小排序 a[j 1]=a[j]; a[j 1]=temp; for( k=0; k printf(" %d",a[k]); printf("
"); }}/*************************************************************** 主函数:传递给插入排序函数整型数组和长度实现排序 ***************************************************************//*void main(void){ int i=0; int j=0; int a[]={9,8,5,3,2}; for( i=0; i printf(" %d",a[i]); printf("
"); InsertSort(a,5); for( i=0; i printf(" %d",a[i]); printf("
");}9 8 5 3 28 9 5 3 25 8 9 3 23 5 8 9 22 3 5 8 92 3 5 8 9*/。收起