#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
}n,*p;
struct node* create(void)
{
struct node *phead=(struct node*)malloc(sizeof(struct node*));
if(phead==NULL)
{
printf("分配地址失败");
exit(-1);
}
return phead;
}
void input(struct node* phead,int d)
{
struct node* last=(struct node*)malloc(sizeof(struct node*));
if(last==NULL)
{
printf("地址分配失败");
exit(-1);
}
last->next=NULL;
last->data=d;
while(phead->next!=NULL)
phead=phead->next;
phead->next=last;
}
void show(struct node* head)
{
int i=1;
while(head->next!=NULL)
{
head=head->next;
printf("%d",head->data);
i++;
}
printf("%d",i);
}
int main(void)
{
struct node* pp = create();
input(pp,1);
input(pp,2);
input(pp,3);
input(pp,4);
show(pp);
return 0;
}
编译没有问题,但是没有任何输出。。求大佬解答
#include<stdlib.h>
struct node
{
int data;
struct node * next;
}n,*p;
struct node* create(void)
{
struct node *phead=(struct node*)malloc(sizeof(struct node*));
if(phead==NULL)
{
printf("分配地址失败");
exit(-1);
}
return phead;
}
void input(struct node* phead,int d)
{
struct node* last=(struct node*)malloc(sizeof(struct node*));
if(last==NULL)
{
printf("地址分配失败");
exit(-1);
}
last->next=NULL;
last->data=d;
while(phead->next!=NULL)
phead=phead->next;
phead->next=last;
}
void show(struct node* head)
{
int i=1;
while(head->next!=NULL)
{
head=head->next;
printf("%d",head->data);
i++;
}
printf("%d",i);
}
int main(void)
{
struct node* pp = create();
input(pp,1);
input(pp,2);
input(pp,3);
input(pp,4);
show(pp);
return 0;
}
编译没有问题,但是没有任何输出。。求大佬解答
