解题思路:
注意事项:
参考代码:
#include<iostream>
#include<cstdio>
using namespace std;
#define MAXSIZE 1005
typedef int KeyType;
typedef struct
{
KeyType Key;
//InfoType otherinfo;
}LineList;
void InsertSort(LineList r[],int n)
{
int i,j;
for(i=2;i<=n;i++)
{
r[0]=r[i];
for(j=i-1;r[0].Key<r[j].Key;j--)
r[j+1]=r[j];
r[j+1]=r[0];
}
}
void output(LineList r[],int n)
{
for(int i=1;i<=n;i++)
cout<<r[i].Key<<" ";
cout<<endl;
}
void input(LineList r[],int n)
{
for(int i=1;i<=n;i++)
cin>>r[i].Key;
}
int main()
{
LineList a[MAXSIZE];
int n;
cin>>n;
input(a,n);
InsertSort(a,n);
output(a,n);
}
0.0分
0 人评分