C语言,链表反转

struct Node{
    struct Node* next;
    int data;
};

typedef struct Node  NODE;

NODE* invert_link_list2(NODE* head)
{
    if(head == 0){
        return 0;
    }
    
    NODE* xpre = head;
    NODE* x = head->next;

    for(; xpre->next != 0; x = xpre->next)
    {
        xpre->next = x->next;
        x->next = head;
        head = x;
    }

    return head;
}

 

你可能感兴趣的:(C语言)