#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef struct list
{
int data;
struct list *next;
}LNode;
void reverse(LNode *h)
{
LNode *p,*q;
p=h->next;
h->next=NULL;
while(p)
{
q=p->next;
p->next=h->next;
h->next=p;
p=q;
}
}
LNode *creatlist(int *a)
{
LNode *h,*p,*q;
int i;
h=p=(LNode *)malloc(sizeof(LNode));
for(i=0; i<N; i++)
{
q=(LNode *)malloc(sizeof(LNode));
q->data=a[i];
p->next=q;
p=q;
}
p->next=0;
return h;
}
void outlist(LNode *h)
{
LNode *p;
p=h->next;
if (p==NULL)
printf("\nThe list is NULL!\n");
else
{
printf("\nHead");
do {
printf("->%d",p->data);
p=p->next;
} while(p!=NULL);
printf("->End\n");
}
}
main( )
{
LNode *A;
int a[N]={4,10,7,5,9};
A=creatlist(a);
reverse(A);
outlist(A);
}