Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26752
  • 博文数量: 41
  • 博客积分: 185
  • 博客等级: 入伍新兵
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-20 13:48
文章分类

全部博文(41)

文章存档

2013年(20)

2012年(21)

我的朋友
最近访客

分类: C/C++

2013-01-05 14:16:03


点击(此处)折叠或打开

  1. //链表逆序
  2. #include"stdlib.h"
  3. typedef struct code
  4. {
  5.     int data;
  6.     struct code *next;
  7. }Code;

  8. Code *Reverse(Code *head)
  9. {
  10.     Code *cur,*pre,*temp;
  11.     if(head==NULL||head->next==NULL)
  12.         return head;
  13.     cur=head;
  14.     pre=NULL;
  15.     while(cur)
  16.     {
  17.         temp=pre;
  18.         pre=cur;
  19.         cur=cur->next; //a a、b顺序不能反;
  20.         pre->next=temp;//b
  21.     }
  22.     return pre;
  23. }

注意:a、b前后顺序不能倒置。若倒置,cur指向第一个元素,cur->next==NULL,循环中断。
阅读(314) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~