#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
int data;
struct node *next;
};
struct node *pHead = NULL;
void display(void )
{
struct node *p;
p = pHead;
while(NULL != p)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n\r");
}
void insert(struct node *pNode)
{
struct node *p;
#if 1
if(NULL == pHead)
{
pHead = pNode;
pHead->next = NULL;
}
else
{
p = pHead;
while(NULL != p->next)
{
p = p->next;
}
p->next = pNode;
pNode->next = NULL;
}
#else
if(NULL == pHead)
{
pHead = pNode;
pHead->next = NULL;
}
else
{
pNode->next = pHead;
pHead = pNode;
}
#endif
return;
}
void list_Reversion(void )
{
struct node *pre, *cur, *ne;
pre = pHead;
cur = pHead->next;
while(NULL != cur)
{
ne = cur->next;
cur->next = pre;
pre = cur;
cur = ne;
}
pHead->next = NULL;
pHead = pre;
}
int main(void )
{
int i;
struct node *p;
for(i = 0; i < 11; i++)
{
p = malloc(sizeof(struct node));
p->data = i;
insert(p);
}
display();
list_Reversion();
display();
return 0;
}