m0_51321956
m0_51321956
2021-04-05 11:10
采纳率: 50%
浏览 25

为什么链表能输入但没有输出

#include<stdio.h>
#include<malloc.h>
typedef struct Polynode
{
	int coef;
	int exf;
	struct Polynode *next;}*Polylist;
void Init(Polylist *l)
{
	*l=(Polylist)malloc(sizeof(Polynode));
	(*l)->next=NULL;}
void Creat(Polylist l)
{
	Polynode *r,*s;
	r=l;
	int c,e;
	scanf("%d%d",&c,&e);
	while(c!=0)
	{
		s=(Polynode*)malloc(sizeof(Polynode));
		s->coef=c;s->exf=e;
		s->next=r;
		r=s;
		scanf("%d%d",&c,&e);}
	r->next=NULL;
}
void Printf(Polylist l)
{
	Polynode *p=l->next;
	while(p!=NULL)
	{
		printf("%d %d\n",p->coef,p->exf);
		p=p->next;}
}
int main()
{
	Polylist l;
	Init(&l);
	Creat(l);
	Printf(l);
	return 0;
}

 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qq_43414873
    小白小白你好菜 2021-04-05 13:18
    已采纳

    就改了一下你的create函数

    #include<stdio.h>
    #include<malloc.h>
    typedef struct Polynode
    {
    	int coef;
    	int exf;
    	struct Polynode *next;
    }*Polylist;
    
    void Init(Polylist *l)
    {
    	*l =(Polylist)malloc(sizeof(Polynode));
    	(*l)->next = NULL;
    }
    
    void Creat(Polylist l)
    {
    	Polynode *r,*s;
    	r = l;
    	int c,e;
    	scanf("%d%d",&c,&e);
    	while(c != 0)
    	{
    		s = (Polynode*)malloc(sizeof(Polynode));
    		s->coef = c;
    		s->exf = e;
    		s->next = NULL;
    		r->next = s;
    		r = s;
    		scanf("%d%d",&c,&e);
    	}
    }
    
    void Printf(Polylist l)
    {
    	Polynode *p = l->next;
    	while(p != NULL)
    	{
    		printf("%d %d\n", p->coef, p->exf);
    		p = p->next;}
    }
    int main()
    {
    	Polylist l;
    	Init(&l);
    	Creat(l);
    	Printf(l);
    	return 0;
    }
    
    点赞 1 评论
  • qq_43414873
    小白小白你好菜 2021-04-05 12:07

    你是想循环链表还是头插法链表或者尾插法链表?

    点赞 1 评论

相关推荐