-
Notifications
You must be signed in to change notification settings - Fork 10
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
丁霆霄(链表倒序)已改 #7
Labels
通过
代码通过考核
Comments
#include<stdio.h>
#include<stdlib.h>
#define L sizeof(struct S)
struct S
{
int num;
int score;
struct S *next;
};
int n;
struct S *creat()
{
struct S *head;
struct S *p1,*p2;
head=NULL;
p1=p2=(struct S*)malloc(L);
printf("输入链表(以0 0结束)\n");
scanf("%d%d",&p1->num,&p1->score);
n=0;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else
{
p2->next=p1;
}
p2=p1;
p1=(struct S*)malloc(L);
scanf("%d%d",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
struct S *unsort(struct S *head)
{
struct S *p1,*p2;
p1=head->next;
p2=head;
p2->next=NULL;
if(p1==NULL)return head;
if(p1->next==NULL)
{
head=p1;
p1->next=p2;
return head;
}
while(p1->next!=NULL)
{
head=p1->next;
p1->next=p2;
p2=p1;
p1=head;
}
p1->next=p2;
return head;
}
void print(struct S *head)
{
struct S *p;
p=head;
while (p!=NULL)
{
printf("%d %d\n",p->num,p->score);
p=p->next;
}
}
int main()
{
struct S *head;
head=creat();
head=unsort(head);
print(head);
return 0;
} |
|
点评:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: