Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

张世杰 链表倒序(已修改) #13

Open
ZSJ6 opened this issue Nov 27, 2018 · 1 comment
Open

张世杰 链表倒序(已修改) #13

ZSJ6 opened this issue Nov 27, 2018 · 1 comment
Labels
修改 代码出现问题,请修改后重新提交代码

Comments

@ZSJ6
Copy link

ZSJ6 commented Nov 27, 2018

#include<stdio.h>
#include<stdlib.h>
struct Student{
	int num;
	char name[20];
	struct Student *next;
};
struct Student *creat()
{
	struct Student *head = NULL,*end,*pnew;
	pnew=(struct Student*)malloc(sizeof(struct Student));
        printf("请输入学号");
	scanf("%d",&pnew->num);
        printf("请输入姓名");
	scanf("%s",&pnew->name);
	int count = 0;
	while(pnew->num != 0)
	{
		count ++;
		if(1 == count)
		{
			pnew->next = head;
			head = pnew;
			end = pnew;
		}
		else
		{
			end->next = pnew;
			end = pnew;
		}
		pnew = (struct Student*)malloc(sizeof(struct Student));
		scanf("%d",&pnew->num);
		scanf("%s",&pnew->name);
	}
	end->next = NULL;
	free(pnew);
	return (head);
}
struct Student *reserve(struct Student *head)
{
	struct Student *p,*pnew = NULL;
	if(head == NULL && head->next == NULL)
	{
		return head;
	}
	p = head;
	while(p != NULL)
	{
		struct Student *temp = p->next;
		p->next = pnew;
		pnew = p;
		p = temp;
		
	}
	return (pnew);
}
void print(struct Student *head)
{
	struct Student *p;
	p = head;
	while(p != NULL)
	{
		printf("请输入学号");
	        scanf("%d",&pnew->num);
                printf("请输入姓名");
		printf("姓名%s\n",p->name);
		p = p->next;
	}
}
int main()
{
	struct Student *pt;
	pt = creat();
	pt = reserve(pt);
	print(pt);
	system("pause");
	return 0;
}
`
@wanghao15536870732
Copy link
Member

  • 没用使用链表(这个使用的是结构体数组)
  • 不符合题目要求,链表倒序 != 反向输出
  • 用户交互性底,非动态创建

@wanghao15536870732 wanghao15536870732 added 修改 代码出现问题,请修改后重新提交代码 and removed 修改 代码出现问题,请修改后重新提交代码 labels Dec 7, 2018
@ZSJ6 ZSJ6 changed the title 张世杰 链表倒序 张世杰 链表倒序(已修改) Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
修改 代码出现问题,请修改后重新提交代码
Projects
None yet
Development

No branches or pull requests

2 participants