#include "stdio.h"
#include "stdlib.h"
struct Student
{int n;
struct Student *next;
};
int main()
{struct Student *head;
void create(struct Student**);
struct Student* proceed(struct Student*);
void print(struct Student*);
void del(struct Student*);
create(&head);
print(head);
head=proceed(head);
print(head);
del(head);
return 0;
}
void create(struct Student **p)
{struct Student *p1,*p2;
int i,n;
printf("Please input n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{ p1=(struct Student*)malloc(sizeof(struct Student));
p1->n=i;
if(i==1)
*p=p1;
else
p2->next=p1;
p2=p1;
}
p1->next=NULL;
}
void print(struct Student *head)
{struct Student *p=head;
while(p!=NULL)
{printf("%d ",p->n);
p=p->next;
}
printf("/n");
}
struct Student* proceed(struct Student *head)
{struct Student *p1,*p2,*t;
p1=p2=head;
p1=p1->next;
while(p1!=NULL)
{ t=p1->next;
p1->next=p2;
if(p2==head)
p2->next=NULL;
p2=p1;
p1=t;
}
head=p2;
return head;
}
void del(struct Student*head)
{struct Student *p1,*p2;
p1=head;
while(p1!=NULL)
{ p2=p1;
p1=p1->next;
free(p2);
}
}