#include <iostream>
#include <stdio.h>
using namespace std;
void Insert_sort(int a[], int n)
{
for(int j = 1; j < n; j++)
{
int key = a[j];
int k = j - 1;
while(k >= 0 && a[k] > key)
{
a[k+1] = a[k];
k = k - 1;
}
a[k+1] = key;
}
}
int main()
{
int T, i = 0, n, a[100];
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
cin >> T;
n = T;
while(T--)
{
cin>>a[i];
i++;
}
Insert_sort(a,n);
for(i = 0; i < 6; i++)
cout<< a[i]<<" ";
cout<<endl;
fclose(stdin);
fclose(stdout);
return 0;
}插入排序
最新推荐文章于 2025-03-31 10:53:38 发布
本文介绍了一个简单的插入排序算法实现,并通过读取文件中的数据进行排序处理。该程序使用C++编写,从in.txt文件中读取整数并将其排序后输出到out.txt文件的前六项。
2600

被折叠的 条评论
为什么被折叠?



