#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
using namespace std;
#define MAXSIZE 10
int num[MAXSIZE];
void init()
{
for (int i = 0; i < MAXSIZE; i++) num[i] = rand() % 100;//产生MAXSIZE个数据 数据范围为0~~~99;
}
void output()
{
for (int i = 0; i < MAXSIZE; i++)
{
printf("%d ", num[i]);
if (i % 10 == 9) printf("\n");
}
printf("\n");
}
///插入排序 order by asc
void Seqsort()
{
int t, j, k;
for (int i = 1; i < MAXSIZE; i++)
{
t = num[i];
for (j = 0; j < i; j++)
{
if (t < num[j]) break;
}
for (k = i - 1; k>j; k--)
{
num[k + 1] = num[k];
}
num[j] = t;
}
}
int main()
{
srand((unsigned)time(NULL));
init();
output();
//
printf("插入排序:\n");
Seqsort();
/
output();
return 0;
}
27. 插入排序
最新推荐文章于 2022-11-15 23:03:42 发布