参考代码如下:
#include <stdio.h>
#include "string.h"
typedef int S32;
S32 FindMax(S32 unSot[], S32 n)
{
S32 maxNum = 0;
S32 i;
for (i = 0; i < n; i++)
{
if (unSot[i] > unSot[maxNum])
{
maxNum = i;
}
}
return maxNum;
}
#define MAX_NUM 7
int main()
{
S32 unsorted[MAX_NUM] = { 11,66,33,99,22,44,55 };
S32 sorted[MAX_NUM] = { 0 };
S32 i;
S32 index = 0;
for (i = 0; i < MAX_NUM; i++)
{
index = FindMax(unsorted, MAX_NUM);
sorted[i] = unsorted[index];
unsorted[index] = -1;
}
memcpy(unsorted, sorted, sizeof(sorted));
}
有好几种排序方法,思路都不一样,可以从冒泡排序看起