这道题是个基础题目,应该难度也不大。
储存结构:
typedef struct{
ElemType *elem;
int length;
}SqList;
函数:
int SqInsert(SqList &L,ElemType e);
输入格式:
输入数据有1行,首先给出以-1结束的非递减顺序表元素值(不超过100个,-1不属于顺序表元素,),然后是被插入元素值。所有数据之间用空格分隔。
输入样例:4 8 20 -1 10
输出样例:Insertion Success.The elements of the SequenceList L are: 4 8 10 20
程序代码:int SqInsert(SqList &L,ElemType e)
{
int i;
if(L.length==MAXSIZE)
return 0;
for(i=L.length-1;i>-1&&L.elem[i]>e;i--)
{
L.elem[i+1]=L.elem[i];
}
L.elem[i+1]=e;
L.length++;
return 1;
}