将数字插入有序排放的数列
输入一个数到有序排放的数列中,插入后,数列仍然有序#include <stdio.h>
#include <stdlib.h>
#define NUM 10
void insert(int *a,int x)
{int i,j=0;
int *n;
for(i=0;i<NUM; i++)
{ for(j=0;x<a[i];j++) j=i-1;}
for(i=NUM;i>=j;j--)a[i+1]=a[i];
a[j]=x;
n[NUM+1]=a[i+1];
}
void arrout(int a[],int n)
{int i;
for(i=0;i<n;i++) printf("%5d",a[i]);
printf("\n");
}
main()
{ int i,j,a[NUM]={21,34,44,56,67,78,89,90,911,912};
int n[NUM+1];
printf("output the primary numbers:\n");
arrout(a,NUM);
printf("input the inserted number:\n");
scanf("%d",&j);
printf("the number needed to insert is: %d\n",j);
insert(a,j);
printf("output the new nubmers:\n");
arrout(n,NUM+1);
system("PAUSE");
return 0;
}
折腾半天了,毛病出在insert那个函数里,compile可以过,但是程序执行到 insert那里不走。怎么改?