梦⁠回⁣从前 2021-06-26 00:28 采纳率: 25%
浏览 26

链表的输出我感觉是没有问题但就是运行不出来

#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
	int score;
	struct student *next;
}Linklist;
Linklist *creat(int n);//输入函数
void newprintf(Linklist *head);
void Pfree(Linklist *head);
int main()
{
	int n=15;
	Linklist *head;
	head=creat(n);
	newprintf(head);
	Pfree(head);
	system("pause");
	return 0;
}
Linklist *creat(int n)
{
	Linklist *head = NULL,*node,*p;
//	for(int i=0;i<n;i++)
	while(p->score!=1)
	{
		node=(Linklist *)malloc(sizeof(Linklist));
		//scanf("%d",&node->score);
		
		node->next = NULL;
		if(head == NULL)
		{
			node->score=n;
			head = node;
			head->next = NULL;
			p = head;
		}
		else
		{
			if(n%2==0)
				node->score=n/2;
			else
				node->score=3*n+1;
			n=node->score;
			p->next = node;
			p = node;
		}
	}
	p->next=NULL;
	return head;
}
void newprintf(Linklist *head)
{
	Linklist *p = head;
	if(p==NULL)
	{
		printf("此链表为空\n");
		return;
	}
	while(p!=NULL)
	{
		printf("我是%d\n",p->score);
		p=p->next;
	}
}
void Pfree(Linklist *head)
{
	Linklist *p = head;
	while(p!=NULL)
	{
		p=head->next;
		free(head);
		head=p;
	}
}

问题在哪

  • 写回答

1条回答 默认 最新

  • 梦⁠回⁣从前 2021-06-26 20:47
    关注
    Linklist *creat(int n)//创造链表
    {
    	Linklist *head=NULL,*node,*end;
    	end=(Linklist *)malloc(sizeof(Linklist));
    	end->next=NULL;
    	end->score=0;
    	for(int i=0;end->score!=1;i++)
    	{
    		node=(Linklist *)malloc(sizeof(Linklist));
    		//scanf("%d",&node->score);
    		node->next=NULL;
    		if(head==NULL)
    		{
    			node->score=n;
    			head=node;
    			head->next=NULL;
    			end=head;
    		}
    		else
    		{
    			if(n%2==0)
    				node->score=n/2;
    			else
    				node->score=3*n+1;
    			n=node->score;
    			end->next=node;
    			end=node;
    		}
    	}
    	end->next=NULL;
    	return head;
    }
    评论

报告相同问题?

悬赏问题

  • ¥15 校内二手商品转让网站
  • ¥20 高德地图聚合图层MarkerCluster聚合多个点,但是ClusterData只有其中部分数据,原因应该是有经纬度重合的地方点,现在我想让ClusterData显示所有点的信息,如何实现?
  • ¥100 求Web版SPC控制图程序包调式
  • ¥20 指导如何跑通以下两个Github代码
  • ¥15 大家知道这个后备文件怎么删吗,为啥这些文件我只看到一份,没有后备呀
  • ¥15 C++为什么这个代码没报错运行不出来啊
  • ¥15 一道ban了很多东西的pyjail题
  • ¥15 关于#r语言#的问题:如何将生成的四幅图排在一起,且对变量的赋值进行更改,让组合的图漂亮、美观@(相关搜索:森林图)
  • ¥15 C++识别堆叠物体异常
  • ¥15 微软硬件驱动认证账号申请