【问题描述】设顺序表S中的数据元素递增有序。试编写程序,将数据x插入顺序表S,要求插入后保持该表的有序性。
【输入形式】
【输出形式】
【样例输入】8
25 28 36 78 96 102 980 1000
88
【样例输出】25 28 36 78 88 96 102 980 1000
【样例说明】设置表长为8
原顺序表s:25 28 36 78 96 102 980 1000
插入数据:8
#include <stdio.h>
#include <stdlib.h>
#define initsize 20
#define LISTINCREMENT 5
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
void IntiList(SqList &L,int n)
{
L.elem=(ElemType *)malloc(n*sizeof(ElemType));
if(!L.elem)
exit(1);
L.length=n;
L.listsize=initsize;
}
int ListInsert(SqList &L,int i,ElemType x)
{
if(L.length+1>=L.listsize)
{
return 0;
}
for(int j=L.length;j>=i;j--)
L.elem[j]=L.elem[j-1];
L.elem[i-1]=x;
L.length++;
}
int main()
{
int n,i;
ElemType x,*p;
SqList L;
printf("\n");
scanf("%d",&n);
IntiList(L,n);
printf("\n");
scanf("%d",&x);
for(i=1,p=L.elem;p<L.elem+L.length&&*p<x;p++)
{
++i;
}
ListInsert(L,i,x);
for(int h=0;h<L.length;h++)
printf("%d",L.elem[h]);
return 0;
}
该怎么修改这个代码