数据结构, 如何将一个数用尾插法插入到链表中,下面是代码,请大神指出哪里出了问题谢谢
#include<stdio.h>#include<stdlib.h>structnode{intdata;structnode*next;};structnode*cr...
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *createlist()
{
struct node *head=NULL;
head=(struct node *)malloc(sizeof(struct node));
head->data=0;
head->next=NULL;
return head;
}
int insertlist(struct node *head,int num)
{
struct node *p,*r;
p=(struct node *)malloc(sizeof(struct node));
r=head;
p->data=num;
r->next=p;
r=p;
}
int showlist(struct node *head)
{
struct node *temp;
temp=head->next;
while(temp)
{
printf("%d\n",temp->data);
temp=temp->next;
}
return 0;
}
int main()
{
struct node *head;
head=createlist();
insertlist(head,9);
insertlist(head,8);
insertlist(head,7);
insertlist(head,5);
showlist(head);
} 展开
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *createlist()
{
struct node *head=NULL;
head=(struct node *)malloc(sizeof(struct node));
head->data=0;
head->next=NULL;
return head;
}
int insertlist(struct node *head,int num)
{
struct node *p,*r;
p=(struct node *)malloc(sizeof(struct node));
r=head;
p->data=num;
r->next=p;
r=p;
}
int showlist(struct node *head)
{
struct node *temp;
temp=head->next;
while(temp)
{
printf("%d\n",temp->data);
temp=temp->next;
}
return 0;
}
int main()
{
struct node *head;
head=createlist();
insertlist(head,9);
insertlist(head,8);
insertlist(head,7);
insertlist(head,5);
showlist(head);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询