wearetheworld1234 于 2017.01.15 11:33 提问

/*
void print(ELemType c) //显示错误的地方！
{
printf("%d",c);

}
*/
//头文件省略

define ERROR 0;

typedef int Status;

typedef int ElemType;

struct LNode

{

``````ElemType data;

LNode * next;
``````

};

//逆位序（节点插在表头）输入n个元素的值，建立带表头结点的单链线性表L

{
int i;

``````L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
printf("请输入%d个数据\n",n);

for(i = n;i > 0;i--)
{
scanf("%d",&p->data);
p->next = L->next;
L->next = p;
}
``````

}

//正位序（结点插在表尾）输入n个元素的值，建立带头结点的单链线性表L；

{
int i;

``````L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
q = L;

printf("请输入%d个数据\n",n);

for(i = 1;i <= n;i++)
{

scanf("%d",&p->data);

q->next = p;  //注意不是L->next = p，因为每次插入是插在上个节点的后面
q = q->next;
}

p->next = NULL;
``````

}

{
LinkList pa = La->next,pb = Lb->next,pc;
Lc = pc = La;

``````while(pa && pb)
if(pa->data <= pb->data)
{
pc->next = pa;
pc = pa;
pa = pa->next;
}
else
{
pc->next = pb;
pc = pb;
pb = pb->next;

}

pc->next = pa ? pa : pb;
free(Lb);
Lb = NULL;
``````

}

{

``````while(p)
{
visit(p->data);
p = p->next;
}

printf("\n");
``````

}

**void print(ELemType c) //显示错误的地方！

{

printf("%d",c);

}**

void main()
{
int n = 5;
printf("按非递减顺序,");
CreateList(La,n);
printf("La = ");
ListTraverse(La,print);

``````printf("按非递减顺序,");
CreateList(Lb,print);
printf("Lb = ");
ListTraverse(Lb,print);

MergeList(La,Lb,Lc);
printf("Lc = ");
ListTraverse(Lc,print);
``````

}

/*
error C2065: 'ELemType' : undeclared identifier

//不理解这儿：我前面已经用 typedef int ElemType 定义了ElemType，为什么此处还提示这样的错误信息！

error C2146: syntax error : missing ')' before identifier 'c'

//这个我也不明白了

error C2182: 'print' : illegal use of type 'void'

//这个print是通过调用ListTraverse来实现的，就应该是void型，此处为什么不正确

error C2059: syntax error : ')'
*/

5个回答

YXTS122   2017.01.15 12:51

ELemType和ElemType，两个单词一样吗

YXTS122 CreateList(Lb,print);这个估计是你粗心写错了，应该是CreateList(Lb,n);

YXTS122 ElemType print(ElemType c){return c;}改为这样

wearetheworld1234 对对对，这个您说的对，我确实没注意到，但是那个void print函数是怎么回事？

YXTS122   2017.01.15 13:27

CreateList(Lb,print(n));

wearetheworld1234 谢谢您的回答，但是我不怎么理解，不好意思啊，能再给我说一下吗？

wearetheworld1234   2017.01.15 11:34

YXTS122   2017.01.15 13:07

ElemType print(ElemType c)
{
return c;
}

YXTS122 (*visit)(p-＞data);改一下这个

YXTS122   2017.01.16 12:07

#include＜stdio.h＞
#include＜stdlib.h＞
#define OK 1

#define ERROR 0

typedef int Status;
typedef int ElemType;
struct LNode
{
ElemType data;
struct LNode * next;
};
//逆位序（节点插在表头）输入n个元素的值，建立带表头结点的单链线性表L
{
int i;
L-＞next = NULL;
printf("请输入%d个数据\n",n);
for (i = n;i ＞0;i--)
{
scanf("%d",&p-＞data);
p-＞next = L-＞next;
L-＞next = p;
}
}
//正位序（结点插在表尾）输入n个元素的值，建立带头结点的单链线性表L；
{
int i;
L-＞next = NULL;
q = L;
printf("请输入%d个数据\n",n);
for (i = 1;i ＜= n;i++)
{
scanf("%d",&p-＞data);
q-＞next = p;
//注意不是L-＞next = p，因为每次插入是插在上个节点的后面
q = q-＞next;
}
p-＞next = NULL;
}
{
LinkList pa = La-＞next,pb = Lb-＞next,pc;
Lc = pc = La;
while (pa && pb)
if (pa-＞data ＜= pb-＞data)
{
pc-＞next = pa;
pc = pa;
pa = pa-＞next;
}
else
{
pc-＞next = pb;
pc = pb;
pb = pb-＞next;
}
pc-＞next = pa ? pa : pb;
free(Lb);
Lb = NULL;
}
void print(ElemType c)
{//显示错误的地方
printf("%d",c);
}
{
while (p)
{
(*visit)(p-＞data);
p = p-＞next;
}
printf("\n");
}
int main()
{
int n = 5;
printf("按非递减顺序,");
CreateList(La,n);
printf("La = ");
ListTraverse(La,print);
printf("按非递减顺序,");
CreateList(Lb,n);
printf("Lb = ");
ListTraverse(Lb,print);
MergeList(La,Lb,Lc);
printf("Lc = ");
ListTraverse(Lc,print);
}