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

许志茹 链表倒序 #8

Open
xzr912 opened this issue Nov 26, 2018 · 0 comments
Open

许志茹 链表倒序 #8

xzr912 opened this issue Nov 26, 2018 · 0 comments

Comments

@xzr912
Copy link

xzr912 commented Nov 26, 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));
	scanf("%d",&pnew->num);
	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("学号%d  ",p->num);
		printf("姓名%s\n",p->name);
		p = p->next;
	}
}
int main()
{
	struct Student *pt;
	pt = creat();
	pt = reserve(pt);
	print(pt);
	system("pause");
	return 0;
}
@xzr912 xzr912 closed this as completed Nov 26, 2018
@xzr912 xzr912 reopened this Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant