#include"stdio.h"
#define SIZE 6
#define LEN sizeof(struct point)
struct point
{
int n;
struct point *next;
};
main()
{
struct point *p,*q,*t,*head;
int i,j;
/* Create the link */
q=p=(struct point *) malloc(LEN);
printf("int node0-n:");
scanf("%d",&p->n);
head=p;
q->next=p;
for(i=1;i<SIZE;i++)
{
p=(struct point *) malloc(LEN);
printf("int node%d-n:",i);
scanf("%d",&p->n);
q->next=p;
q=p;
}
q->next=NULL;
/*Reverse the link. */
p=head;
q=head->next;
t=q->next;
head->next=NULL;
q->next=p;
for(i=1;i<SIZE-2;q->next=p,i++)
{
p=q;
q=t;
t=t->next;
}
t->next=q;
head=t;
/* Print the reversed link*/
p=head;
for(i=0;i<SIZE;i++)
{
printf("node%d.n=%d\n",i,p->n);
p=p->next;
}
}
[此贴子已经被作者于2006-12-8 19:55:35编辑过]