【链表】将一个链表反转

来源:互联网 发布:mac比特币病毒怎么破解 编辑:程序博客网 时间:2024/06/06 04:08

typedef struct linknode

{

    int data;

    struct linknode *next;

}node;

 

//将一个链表逆置

node *reverse(node *head)

{

    if ( head == NULL || head->next == NULL )

    {

        return head;

    }


    node *p,*q,*r;

    p=head;

    q=p->next;


    while(q!=NULL)

    {

        r=q->next;

        q->next=p;

        p=q;

        q=r;

    }

 

    head->next=NULL;

    head=p;

    return head;

}

原创粉丝点击