Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4732543
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2009-07-21 19:55:58

  这个没什么好说的,直接上代码了

#include <stdio.h>
#include <stdlib.h>

#define N 10

typedef struct list
{
  int num;
  struct list* next;
}LIST;

void init_list(LIST** L)
{
  *L = (LIST*)malloc(sizeof(LIST));
  (*L)->next = NULL;
}

void add_list(LIST* L, int num)
{
   LIST* p = (LIST*)malloc(sizeof(LIST));
   p->num = num;
   p->next = L->next;
   L->next = p;
}

void printf_list(LIST* L)
{
  LIST* p = L->next;
  while(p!=NULL)
   {
     printf("%d\t",p->num);
     p = p->next;
   }
}

void revert_list(LIST* L)
{
  LIST* pNode = L->next;
  LIST* Prev = NULL;
  LIST* Next = NULL;
  
  while(pNode!=NULL)
   {
     Next = pNode->next;
     if(Next == NULL)
       L->next = pNode;
       
     pNode->next = Prev;
     Prev = pNode;
     pNode = Next;
   }
}

int main(int argc, char *argv[])
{
  int i = 0;
  int num;
  LIST* L = NULL;
  srand((unsigned)time(NULL));
  init_list(&L);
  
  for(; i<N; i++)
   {
    num = rand()%100+1;
    add_list(L, num);
   }
  
  printf("The original list is:\n");
  printf_list(L);
  revert_list(L);
  printf("After revert the list is:\n");
  printf_list(L);
  system("PAUSE");    
  return 0;
}

阅读(762) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-07-29 16:41:54

谷易歌专职于,通过[url=http://www.555920.cn]google推广[/URL]可以使潜在客户互联网客户很快很容易的找到你的公司,很快的找他自己所需产品我们的服务有[url=http://www.555920.cn]北京google推广[/URL]、[url=http://www.555920.cn]北京google优化[/URL]、[url=http://www.555920.cn/guangzhou.htm]广州google优化[/URL]、[url=http://www.555920.cn/guangzhou.htm]广州google推广[/URL]、、[url=http://www.555920.cn/xiamenguge.htm]厦门google优化[/URL]、[url=http://www.555920.cn/xiamenguge.htm]厦门google推广[/URL]、[url=http://www.555920.cn/hangzhouseo.htm]杭州google推广[/URL]、[url=http://www.555920.cn/hangzho