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




2007-09-04 16:48
2007-09-04 16:56
正好有现成的,前两天写的,自己看看吧
#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;
}

2007-09-04 17:03
2007-09-12 12:04
2007-09-12 12:58