结构体链表 C语言 求大虾帮忙解决编译问题

来源:百度知道 编辑:UC知道 时间:2024/06/30 04:57:09
#include<stdio.h>
#include<stdlib.h>
#define NULL 0
#define LENG sizeof(struct Lnode)

struct Lnode{
int data;
struct Lnode *next;
};

struct Lnode *creat()
{
struct Lnode *head,*tail,*p;
int e;
head=(struct Lnode *)malloc(LENG);
tail=head;
do{ p=(struct Lnode *)malloc(LENG);
scanf("%d",&e);
p->data=e;
tail->next=p;
tail=p;
}
while(p!='\0');
tail->next=NULL;
return head;
}

int leng(struct Lnode *head)
{
int length=0;
struct Lnode *p;
p=head->next;
while(p->next!=NULL)
{
printf("%d",p->data);
length++;
p=p->next;
}
return length;
}

int max(struct Lnode *head)
{
int max=0;
struct Lnode *p;
p=head->next;
while(p->next!=NULL)
{
if(max<p-

//问题原因:主函数main单词拼写错误,struct Lnode在主函数重复定义
//q=(struct Lnode *)*creat(); 返回值类型错误,以下是修改过的代码
//编译可以通过
#include<stdio.h>
#include<stdlib.h>
#define NULL 0
#define LENG sizeof(struct Lnode)

struct Lnode{
int data;
struct Lnode *next;
};

struct Lnode *creat()
{
struct Lnode *head,*tail,*p;
int e;
head=(struct Lnode *)malloc(LENG);
tail=head;
do{ p=(struct Lnode *)malloc(LENG);
scanf("%d",&e);
p->data=e;
tail->next=p;
tail=p;
}
while(p!='\0');
tail->next=NULL;
return head;
}

int leng(struct Lnode *head)
{
int length=0;
struct Lnode *p;
p=head->next;
while(p->next!=NULL)
{
printf("%d",p->data);
length++;
p=p->next;
}
return length;
}

int max(str