C语言单链表小程序为何不能通过编译

来源:百度知道 编辑:UC知道 时间:2024/04/29 05:29:20
功能:建立两个单链表a和b,删除b链表中数据域与a链表中数据域相同的结点。最后输出a和b
#include "stdio.h"
#include "malloc.h"
struct linklist
{int xh;
struct linklist *next;
};

struct linklist *creat(int m)/*建表函数*/
{int i;
struct linklist *head,*q=head,*p;

head=(struct linklist *)malloc(sizeof(struct linklist));
for(i=0;i<m;i++)
{p=(struct linklist *)malloc(sizeof(struct linklist));
scanf("%d",&p->xh);
q->next=p;
q=p;
}
p->next=0;
return head;
}

struct linklist *del(struct linklist *h,struct linklist *r)/*删除查找到的b中结点*/
{struct linklist *m=h;
while(m->next!=r)
m=m->next;
r->next=r->next->next;
return h;
}

void search(struct linklist *a,struct linklist *b)/*查找b中与a数据域相同的结点*/
{struct linklist *r=b;
while(a->next)
{
for(r=b;r->next;r=r->next)
if(a->next->xh==r->next->xh)

#include "stdio.h"
#include "malloc.h"
struct linklist
{
int xh;
struct linklist *next;
};

struct linklist *creat(int m)/*建表函数*/
{
int i;
struct linklist *head, *q, *p;

head=(struct linklist *)malloc(sizeof(struct linklist));
q = head;
for(i=0;i<m;i++)
{
p=(struct linklist *)malloc(sizeof(struct linklist));
scanf("%d",&p->xh);
q->next=p;
q=p;
}
p->next=NULL;
return head;
}

void del( struct linklist *h, struct linklist *r)/*删除查找到的b中结点*/
{
while ( h->next != r && h->next != NULL )
{
h = h->next;
}
if ( h->next != NULL )
{
h->next = r->next;
free( r );
r = NULL;
}
}

void search(struct linklist *a,struct linklist *b)/*查找b中与a数据域相同的结点*/
{
struct linklist *r=b;