Data Structure--Reverse LinkList

The original Linklist is as diagram shown:

 the codes are following
   
 node *reverse(node *head)
  {
    node *p1,*p2,*p3;
    if(head==NULL || head->next=-NULL)
    return head;
    //p1-->previous pointer
    //p2-->current pointer
    //p3-->next pointer
    p1=head;
    p2=p1->next;
    while(p2)
    {
    p3=p2->next;
    p2->next=p1;
    p1=p2;
    p2=p3;
    }

    head->next=NULL;
    head=p1;
    return head;
  }

posted on 2008-02-26 11:46  飞天舞者  阅读(375)  评论(0编辑  收藏  举报

导航

For more information about me, feel free email to me winston.he@hotmail.com