//函数功能:把链表相邻元素反转 //输入参数:head:指向链表头结点 void reverse(Node* head){ if (head == NULL || head->next == NULL) return ; Node *pre = head, *cur = head->next, *next = NULL; while (cur != NULL && cur->next != NULL) { next = cur->next->next; pre->next = cur->next; cur->next->next = cur; cur->next = next; pre = cur; cur = next; } }
原文地址:https://www.cnblogs.com/fuqia/p/10262485.html
时间: 2024-10-18 20:27:36