[求助]怎样在顺序表第i个位置插入一个元素
请教大家一下:怎样在顺序表第i个位置插入一个元素

by 雨中飞燕 QQ:78803110 QQ讨论群:5305909



[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
正好有现成的,前两天写的,自己看看吧
#define MaxSize 100
typedef int DataType;
typedef struct
{
DataType list[MaxSize];
int size;
}SeqList;
int SeqList_Insert(SeqList *L,int pos,DataType add) //线性表的插入
{
if(L->size>=MaxSize)
{
printf("the list is full\n");
return 0;
}
if(pos>L->size)
{
printf("the pos is not exsit");
return 0;
}
int i;
for(i=pos;i<L->size;i++)
L->list[i+1]=L->list[i];
L->list[pos]=add;
L->size++;
printf("\nthe number you insert is %d,it's pos is %d",add,pos);
return 1;
}