1)原理:对于一个将要排序的数组A[n],先找出最小元素(升序排列),将其与A[0]交换,接着在数组下标为1~n-1的元素中寻找最小值,与A[1]交换,直到排序结束。
2)C语言实现:
void main()
{
int t,temp,count, *p;
printf("please input the count :");
scanf_s("%d", &count);
p = (int *)malloc(count * 2);
printf("\nplease input the number to be sorted : \n");
for (int i = 0; i < count; i++)
{
scanf_s("%d", p+i);
}
for (int i = 0; i < count; i++)
{
t = i;
for (int j = i+1; j < count; j++)
{
if (p[t] > p[j])
{
t = j;
}
}
temp = p[t];
p[t] = p[i];
p[i] = temp;
}
for (int i = 0; i < count; i++)
{
printf("%d ", p[i]);
}
system("pause");
}
3)分析:
原文地址:http://blog.csdn.net/jing_unique_da/article/details/46545639