选择法排序
来源:互联网 发布:网络电影招商方案 编辑:程序博客网 时间:2024/05/16 01:30
#include "stdio.h"
void swap(int *a,int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void selectsort(int data[],int n) /*选择排序*/
{
int i,j,k,max;
//int temp;
for(i=0;i<n-1;i++)// “ i ” 就是起始值
{
k = i;
for(j=i+1;j<n;j++)
{
if(data[j] < data[k])
k = j;//k is the always the smaller data location
}
if(k != i)//move the smallest data to the first location
{
swap(&data[i], &data[k]);
}
}
}
int main()
{
int i,a[10] = {2,5,6,3,7,8,0,9,12,3};
printf("The data array is:\n") ;
for(i=0;i<10;i++) /*显示原序列之中的元素*/
printf("%d ",a[i]);
selectsort(a,10); /*执行选择排序*/
printf("\nThe result of selection sorting for the array is:\n");
for(i=0;i<10;i++)
printf("%d ",a[i]); /*输出排序后的结果*/
printf("\n");
return 0;
}
- 常用排序-选择法排序
- 常见排序-选择法排序
- 排序算法--选择排序法
- 按选择排序法排序。
- 排序模板 选择法排序
- 排序算法--选择排序法
- 排序之选择排序法
- 选择排序法法
- 排序:选择法
- 选择排序法
- 选择法排序
- 选择排序法
- 选择排序法证明
- 选择排序法
- 选择排序法
- 选择排序法
- 选择排序法
- C++ 选择排序法
- Android 编译(一)
- Web调试利器OpenWindow
- UITextView的一些操作
- 健康生活:刘逢军老师养生感悟100条
- Caused by: java.lang.UnsatisfiedLinkError: Couldn't load BaiduMapVOS_v2_1_3: findLibrary returned nu
- 选择法排序
- Java操作oracle数据库
- JavaSE_网络编程_UDP_2
- 必备的JavaScript函数和实用的小技巧
- Android ViewPager使用详解
- jquery实用的电话号码和手机号码验证
- MySQL server has gone away报错原因分析
- 将不确定变为确定~老赵写的CodeTimer是代码性能测试的利器
- jquerymobile页面跳转和参数传递