/*********************************************************************************
* Copyright: (C) 2013 fulinux<fulinux>
* All rights reserved.
*
* Filename: list.c
* Description: This file
*
* Version: 1.0.0(2013年03月12日~)
* Author: fulinux <fulinux@sina.com>
* ChangeLog: 1, Release initial version on "2013年03月12日 12时59分15秒"
*
********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
typedef struct _LINK_NODE
{
int data;
struct _LINK_NODE *next;
}LINK_NODE;
struct _LINK_NODE var;
LINK_NODE *create_list();
void travel_list(LINK_NODE *head);
LINK_NODE *revers_list(LINK_NODE *head);
int main (int argc, char **argv)
{
LINK_NODE *head;
head = create_list();
travel_list(head);
head = revers_list(head);
travel_list(head);
return 0;
} /* ----- End of main() ----- */
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
struct _LINK_NODE *create_list()
{
int i;
char a;
LINK_NODE *head,*rear,*p;
head = (LINK_NODE *)malloc(sizeof(LINK_NODE));
rear = head;
for(i = 0;i < 5;i++)
{
p = (LINK_NODE *)malloc(sizeof(LINK_NODE));
p->data = i;
rear->next = p;
rear = p;
}
rear->next = NULL;
list.c
return head->next;
} /* ----- End of create_list() ----- */
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
void travel_list(LINK_NODE *head)
{
LINK_NODE *p;
p = head;
while(p)
{
printf("%d",p->data);
p = p->next;
}
printf("\n");
} /* ----- End of trave_list() ----- */
/********************************************************************************
* Description:
* Input Args:
* Output Args:
* Return Value:
********************************************************************************/
LINK_NODE *revers_list(LINK_NODE *head)
{
int i = 1;
LINK_NODE *tail,*p,*q;
p = head;
while(head->next)
{
p = head;
do
{
q = p;
p = p->next;
}while(p->next);
if(1 == i)
{
i = 0;
tail = p;
}
p->next = q;
q->next = NULL;
}
return tail;
} /* ----- End of revers_list() ----- */