最近在复习数据结构,整理部分有点绕的点,其中一个就是链表倒转
/* 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;
}