常用排序
来源:互联网 发布:汇编语言转c语言 编辑:程序博客网 时间:2024/04/28 02:42
//C语言选择排序
#include <stdio.h>
#include <conio.h>
void SelectSort ( int array[], int nSize )
{
int nMinIndex;
int nIndex_1, nIndex_2;
for (nIndex_1 = 0;nIndex_1 < nSize - 1 ;nIndex_1++) //这个呢负责把待排序的数列走几趟..
{
nMinIndex = nIndex_1;
for (nIndex_2 = nIndex_1 + 1 ; nIndex_2 < nSize;nIndex_2++) //这个呢..是走一趟.然后找到最值.
{
if ( array[nMinIndex] > array[nIndex_2] )
{
nMinIndex = nIndex_2;
}
}
if ( nMinIndex != nIndex_1 ) //一趟找到最值后,就交换到未排好序的序列的最前面了...
{
int temp = array[nIndex_1];
array[nIndex_1] = array[nMinIndex];
array[nMinIndex] = temp ;
}
}
}
void ShowArray(int array[], int nSize)
{
int i;
for (i = 0; i < nSize; i++)
{
printf("%d/t", array[i]);
if ((i+1)%10 == 0)
{
printf("/n");
}
}
printf("/n");
}
int main()
{
int array[7] = {6, 8, 10, 1, 2, 7, 9};
printf("Old Array:/n");
ShowArray(array, 7);
SelectSort(array, 7);
printf("Sorted Array:/n");
ShowArray(array, 7);
printf("Press any key to exit");
getch();
}
- 常用排序
- 常用排序
- 常用排序
- 常用排序
- 常用排序
- 常用排序
- 常用排序
- 常用排序
- 常用 排序
- 常用排序
- 常用排序-冒泡法排序
- 常用排序-选择法排序
- 常用排序算法--冒泡排序
- 常用排序算法--插入排序
- 常用排序算法--希尔排序
- 常用排序算法--堆排序
- 常用排序算法--归并排序
- 常用排序算法--快速排序
- DataSet对象的属性
- JavaScript中常用的一百零七条语句
- IBM 软件资讯:手机免费上Notes,轻松好礼等你拿!
- C# 日期格式转换
- 100句话浓缩100部名著
- 常用排序
- hd 1887 Weird Numbers
- 常用数据库JDBC连接写法
- 搞笑歇后语集合
- C#日期格式转换大全
- installshield 12较6.0生成MS SQL数据库策略
- 经典代码总结(译)
- 如何简单有效关闭Oracle死锁进程
- 串操作指令