您的位置:首页 > 其它

无题

2015-11-08 15:54 239 查看
#include <stdio.h>
#define N 20
void Insert(int a[],int n,int x);
int main()
{
int a[N+1];
int x,i,n;
printf("Input array size :");
scanf("%d",&n);
printf("Input array:");
for (int i = 0; i < n; ++i)
{
scanf("%d",&a[i]);
/* code */
}
printf("Input x:");
scanf("%d",&x);
Insert(a,n,x);
printf("After insert %d :\n",x);
for (int i = 0; i < n+1; ++i)
{
/* code */
printf("%4d",a[i]);
}
printf("\n");
return 0;
}
void Insert(int a[],int n,int x)
{
int i=0,pos;
while(i<n&&x>a[i])
{
i++;
}
pos = i;
for (int i = n-1; i >= pos; i--)
{
/* code */
a[i+1] = a[i];
}
a[pos] = x;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: