0
点赞
收藏
分享

微信扫一扫

x-pack的破解方式和免费jar包!!可直接用!!

言午栩 03-02 16:30 阅读 2

struct ListNode* get_midlistnode( struct ListNode* head )

{

    struct ListNode* arr = NULL;

    struct ListNode* fast = head->next;

    struct ListNode* slow = head;

    while( fast != NULL && fast->next != NULL )

    {

        fast = fast->next->next;

        slow = slow->next;

    }

    arr = slow->next;

    slow->next = NULL;

    return arr;

}

找中间链点

struct ListNode* test( struct ListNode* head )

{

    struct ListNode* pos = (struct ListNode*)malloc(sizeof(struct ListNode));

    pos->next = head;

    struct ListNode* p1 = head;

    struct ListNode* p2 = head->next;

    while( p2 != NULL )

    {

        p1->next = p2->next;

        p2->next = pos->next;

        pos->next = p2;

        p2 = p1->next;

    }

    return pos->next;

}

将中间链点至最后反转

struct ListNode* test1(struct ListNode* headA , struct ListNode* headB )

{

    struct ListNode* pos = (struct ListNode*)malloc(sizeof(struct ListNode));

    struct ListNode* pf = pos;

    while( headA && headB )

    {

        pf->next = headA;

        headA = headA->next;

        pf = pf->next;

        pf->next = headB;

        headB = headB->next;

        pf = pf->next;

    }

    while( headA )

    {

    pf->next = headA;

    headA = headA->next;

    }

    return pos->next;

}

合并链表

void reorderList(struct ListNode* head){

    struct ListNode* mid_ListNode = NULL;

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

    {

        ;

    }

    else

    {

    mid_ListNode = get_midlistnode(head);

    mid_ListNode = test(mid_ListNode);

    head = test1(head,mid_ListNode);

    }

}

举报

相关推荐

0 条评论