解题思路:
注意事项:
参考代码:
#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二级辅导-计负均正 (C语言代码)浏览:658 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:655 |
C语言程序设计教程(第三版)课后习题9.3 (Java代码)浏览:966 |
A+B for Input-Output Practice (VI) (C++代码)浏览:418 |
【数组的距离】 (C语言代码)浏览:741 |
分糖果 (C++代码)浏览:1447 |
字符串对比 (C语言代码)浏览:1413 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1044 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:338 |
字符逆序 (C语言代码)浏览:646 |