Chinaunix首页 | 论坛 | 博客
  • 博客访问: 635561
  • 博文数量: 263
  • 博客积分: 9025
  • 博客等级: 中将
  • 技术积分: 2567
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-01 17:42
文章分类

全部博文(263)

文章存档

2012年(4)

2011年(64)

2010年(47)

2009年(44)

2008年(99)

2007年(5)

我的朋友

分类: C/C++

2011-04-16 08:29:06


单链表逆置算法

struct node
 {
  int num;
  struct node *next;
 }
 struct node* reverse(struct node *head)
 //head 链表头结点
 {
  struct node *p,*temp1,*temp2;
  if(head==NULL________) return head; //||head->next==NULL
  p=head->next;head->next=NULL;
  while(________) //p!=NULLp
  {
   temp1=head;
   ________; //head=p;
   temp2=p;
   p=p->next;
   ________; //temp2->next=temp1;head->next=temp1;
   }//Match while statenment
   return head; //返回逆置后的链表的头结点
 }



或者

struct node* reverse(struct node *head)
//head 链表头结点
{
  struct node *p,*temp1,*temp2;
  if(head==NULL________) return head; //||head->next==NULL
  p=head->next;head->next=NULL;
  while(________) //p!=NULLp
  {
   temp1=p->next;
   p->next = head;

          head = p;

          p = temp1;

  }//Match while statenment
  return head; //返回逆置后的链表的头结点
}


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