数据结构中遇到的问题error C2016: C 要求一个结构或联合至少有一个成员
代码是:请大神们赐教
#include
#include
#include
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
struct ElemType{
char cityname[20];
int number;
char introduct[20];
};
typedef struct{
ElemType elem[LIST_INIT_SIZE];
int length;
int listsize;
}SqList;
void CreatList_Sq(SqList *&L,ElemType *a,int n){//建立顺序表
L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L->elem) exit(0);
for(int i=0;i
{
strcpy(L->elem[i].cityname,a[i].cityname);
L->elem[i].number=a[i].number;
strcpy(L->elem[i].introduct,a[i].introduct);
}
}
void DisplayList(SqList *&L) //输出线性表
{
for(int i=0;ilength;i++)
printf("%s %d %s\n",L->elem[i].cityname,L->elem[i].number,L->elem[i].introduct);
printf("线性表的长度是:%d\n",L->length);
}
void LocateElem(SqList *&L) //查询线性表中的元素
{
int m;
printf("请输入要查询的城市的区号:");
scanf("%d",&m);
for(int i=0;ilength;i++)
{
if(m==L->elem[i].number)
printf("%s %d %s\n",L->elem[i].cityname,L->elem[i].number,L->elem[i].introduct);
}
}
int ListInsert(SqList *&L,int i){
//在线性表L中第i个位置前插入新的元素,
//i的合法值为1<=i<=L->length+1
ElemType *newbase;
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) exit(0);
L->elem=newbase;
L->listsize+=LISTINCREMENT;
}
char n[20]="GuangDong";
int num=5;
char intro[20]="In southern China";
for(int j=L->length;j>i;j--)
{
strcpy(L->elem[j].cityname,L->elem[j-1].cityname);
L->elem[j].number=L->elem[j-1].number;
strcpy(L->elem[j].introduct,L->elem[j-1].introduct);
}
strcpy(L->elem[i].cityname,n);
L->elem[i].number=num;
strcpy(L->elem[i].introduct,intro);
L->length++;
printf("线性表的长度是:%d\n",L->length);
return 0;
}
void DeletList(SqList *&L,int i)
//删除线性表的第i个元素
{
for(int j=i;jlength;j++)
{
strcpy(L->elem[j].cityname,L->elem[j+1].cityname);
L->elem[j].number=L->elem[j+1].number;
strcpy(L->elem[j].introduct,L->elem[j+1].introduct);
}
L->length--;
printf("线性表的长度是:%d\n",L->length);
}
void DestroyList(SqList *&L)
{
free(L);
}
void main(){
struct ElemType b[4]={
{"BeiJing",1,"capital city"},
{"WuHan",2,"beautiful"},
{"XiaMen",3,"near sea"},
{"HanDan",4,"my home"}
};
SqList *List;
printf("原线性表中的元素是:\n");
CreatList_Sq(List,b,4);