数据结构之-链表倒转

最近在复习数据结构,整理部分有点绕的点,其中一个就是链表倒转

/* Function to reverse the linked list */
static void reverse(struct LNode **head_ref)
{
    struct LNode *prev = NULL;
    struct LNode *current = *head_ref;
    struct LNode *next = NULL;
    while (current != NULL)
    {
        // Store next
        next = current->next;

        // Reverse current node's pointer
        current->next = prev;

        // Move pointers one position ahead.
        prev = current;
        current = next;
    }
    *head_ref = prev;
}
原文地址:https://www.cnblogs.com/johnzhu/p/11103543.html