顺序储存
#include<stdio.h>#include<stdlib.h>
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
void CreatSqList(SqList &L);
int lengthtlist(SqList L);
void ListInsert(SqList &L,int i,int &e);
void PreList(SqList L);
void main()
{
SqList L;
int i;
int data[ ]={1,2,3,4,5,6};
CreatSqList( L);
for(i=0;i<6;i++)
{
ListInsert(L,i+1,data[i]);
}
printf("%d\n",L.length);
PreList(L);
}
void CreatSqList(SqList &L)
{
L.elem=(ElemType*)malloc(100*sizeof(ElemType));
L.length=0;
L.listsize=100;
}
int lengthlist(SqList &L)
{
return (L.length);
}
void ListInsert(SqList &L,int i,ElemType &e)
{
int *p,*q;
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;p--)*(p+1)=*p;
*p=e;
++L.length;
}
int lengthlist(SqList L)
{
return (L.length);
}
void PreList(SqList L)
{
for(int i=0;i<L.length;i++)
printf("%d",*L.elem[i]);
}
为什么老出现 error C2100: illegal indirection