这样操作线性表为设么不行???
代码如下:就是搞不清这个int initlist(sqlist L)和int initlist(sqlist &L)有什么区别???麻烦讲一下。。。谢了
#include<stdio.h>
#include<malloc.h>
#define elemtype int
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
elemtype *elem;
int length;
int listsize;
}sqlist;
int initlist(sqlist L){
L.elem =(elemtype *)malloc(LIST_INIT_SIZE*sizeof(elemtype));
if(!L.elem ) return 0;
L.length=0;
L.listsize =LIST_INIT_SIZE;
return 1;
}
int listinsert(sqlist L,int i,elemtype e){
int *q,*p;
if(i<1&&i>L.length +1) return 0;
if(L.length >=L.listsize ){
newbase=(elemtype *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(elemtype));
if(!newbase) return 0;
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
q=&L.elem[i-1];
for(p=&L.elem[L.length-1];p>=q;--p){
*(p+1)=*p;
}
*q=e;
++L.length ;
return 1;
}
void main()
{
int i,*p,j,a;
sqlist(L);
initlist(L);
scanf("%d",&L.length);
for(i=0;i<L.length;i++){
p=&L.elem[i];
scanf("%d",&p);
}
scanf("%d",&j);
listinsert(L,j,a);
}
应该怎么改啊???