首页 > 用户发贴区 > 编程问题提问区 > 线性表输入数据问题
2008
09-10

线性表输入数据问题

这段代码在向La,Lb复制的时候就老报错,说是类型不一致,刚学数据结构,这一点对线性表的复制总不知道该怎么办 ,谁能帮着解决一下,这里先谢过了

错误是这样的

Compiling…
test.cpp
D:\Microsoft Visual Studio\MyProjects\test\test.cpp(38) : error C2660: ‘InitList’ : function does not take 1 parameters
D:\Microsoft Visual Studio\MyProjects\test\test.cpp(43) : error C2660: ‘ListInsert’ : function does not take 3 parameters
D:\Microsoft Visual Studio\MyProjects\test\test.cpp(44) : error C2660: ‘ListInsert’ : function does not take 3 parameters
D:\Microsoft Visual Studio\MyProjects\test\test.cpp(47) : error C2660: ‘ListInsert’ : function does not take 3 parameters
D:\Microsoft Visual Studio\MyProjects\test\test.cpp(50) : error C2660: ‘ListInsert’ : function does not take 3 parameters
Error executing cl.exe.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OVERFLOW -2
#define OK 1

typedef struct{
int *elem;
int length;
int listsize;
}List;

void main()
{List MergeList(List,List);
 List La,Lb,Lc;

 for(i=0;i<9;i++)
   scanf(“%d”,&La.elem[i]);
 for(i=0;i<10;i++)
  scanf(“%d”,&Lb.elem[i]);

 Lc=MergeList(La,Lb);
}

void MergeList(List La,List Lb,List &Lc)
{List InitList();
 int ListLength(List);
 int GetElem(List,int,int);
 int ListInsert(List);
 int i,j,k,La_len,Lb_len,ai,bj;
InitList(Lc);
i=j=1;k=0;
La_len=ListLength(La);Lb_len=ListLength(Lb);
while((i<=La_len)&&(j<=Lb_len))
{GetElem(La,i,ai); GetElem(Lb,j,bj);
if(ai<=bj) {ListInsert(Lc,++k,ai);++i;}
else{ListInsert(Lc,++k,bj);++j;}
}
while(i<=La_len)
{GetElem(La,i++,ai);ListInsert(Lc,++k,ai);
}
while(i<=Lb_len)
{GetElem(Lb,j++,bj);ListInsert(Lc,++k,bj);
}
}

int ListLength(List L)
{int i;
 i=0;
 while(L.elem[i]!=NULL)
 i++;
}

int InitList(List &L) {
L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem) exit(OVERFLOW);
L.length=LIST_INIT_SIZE;
return OK;
}

int GetElem(List L,int i,int *e) {

if(i<1||i>L.length)
{
printf(“输入非法”);
system(“pause”);
exit(1);
}

*e=L.elem[i-1];
}

int ListInsert(List &L,int i,int e)
{int ListLength(List);
int *newbase,*q,*p;
if(i<1||i>ListLength(L)+1) return 0;
if(L.length>=L.listsize) {
newbase=(int *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(int));
if(!newbase) exit(-2);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;–q) *(p+1)=*p;
*q=e;
++L.length;
return OK;
}


留下一个回复