#include<stdio.h>
#define MAXSIZE 1000
main()
{
int list[1000],result,j,i,n,x;
printf("\nInput the number:\n");
scanf("%d",&n);
printf("\nInput the array!\n");
for (i=0;i<n;i++)
scanf("%d",&list[i]);
printf("\nInput the number you want to insert:\n");
scanf("%d",&x);
printf("\nInput the position you want to insert:\n");
scanf("%d",&j);
result=sq_insert(list,&n,j,x);
switch (result)
{
case 0:
printf("\nInsert successfully!");
for (i=0;i<n;i++)
printf("\n%d\n",list[i]);
break;
case 1:
printf("\nThe insert position is invalid!\n");
break;
case 2:
printf("\nThe list is full!\n");
break;
}
}
int sq_insert(list,p_n,i,x)
int list[1000],x;
int *p_n,i;
{
int j;
if(i<0||i>*p_n)
return(1);
if (*p_n==MAXSIZE)
return(2);
for (j=*p_n;j>i;j--)
list[j]=list[j-1];
list[i]=x;
(*p_n)++;
return(0);
}