解题思路:
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:619 |
C语言训练-尼科彻斯定理 (C语言代码)。。。内含证明定理浏览:2070 |
K-进制数 (C++代码)浏览:858 |
【偶数求和】 (C++代码)浏览:709 |
C语言考试练习题_排列 (C语言代码)浏览:1326 |
九宫重排 (C++代码)浏览:2160 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:600 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:687 |
WU-图形输出 (C++代码)浏览:802 |
【魔板】 (C++代码)(时间超限,希望会的帮我改正一下)浏览:743 |