链表相邻元素翻转,如a->b->c->d->e->f-g,翻转后变为:b->a->d->c->f->e->g 

LNode* ReverseLinkList3(LNode* head)
{
    if(head == NULL)
        return head;
    LNode* p;
    LNode* temp;
    LNode* trail=head;

    while(trail->next !=NULL && trail->next->next != NULL)
    {
                //防止无限循环,在测试是设置一个循环标记位!

        p=trail->next;
        temp=trail->next->next;
        trail->next=temp;
        p->next=temp->next;
        temp->next=p;
        trail=p;
    }

    return head;
}

 

 

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2022-01-03
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2021-07-08
  • 2022-12-23
  • 2022-02-18
相关资源
相似解决方案