https://www.cnblogs.com/eniac12/p/4860642.html
template<class T> void List<T>::Inverse() {if(first == NULL) return;LinkNode<T> *p, *prev, *latter; p = first->link; // 當前結點prev = NULL; // 前一結點latter = p->link; // 下一結點while(p != NULL){p->link = prev; // 當前結點指針指向前一結點prev = p; // 后移p = latter;if(p != NULL) // 如果p指針是NULL,已經滿足終止條件latter = p->link;}first->link = prev;; // 最后連上附加頭結點 }
https://blog.csdn.net/ljyljyok/article/details/77996029
LINK_NODE?*ReverseLink(LINK_NODE?*head)
???{
???? ? LINK_NODE?*next;
???? ? ?LINK_NODE?*prev?=?NULL;
????
???? ? ?while(head?!=?NULL)
???? ? ?{
???? ? ? ? ?next?=?head->next;
???? ? ? ? head->next?=?prev;
???? ? ? ? prev?=?head;
???? ? ? ? head?=?next;
???? ??}
????
???? ? ?return?prev;
????}
http://www.nowamagic.net/librarys/veda/detail/2241
/* 單鏈表反轉/逆序 */ Status ListReverse(LinkList L) {LinkList current,pnext,prev;if(L == NULL || L->next == NULL)return L;current = L->next; /* p1指向鏈表頭節點的下一個節點 */pnext = current->next;current->next = NULL;while(pnext){prev = pnext->next;pnext->next = current;current = pnext;pnext = prev;printf("交換后:current = %d,next = %d \n",current->data,current->next->data);}//printf("current = %d,next = %d \n",current->data,current->next->data);L->next = current; /* 將鏈表頭節點指向p1 */return L; }
http://www.nowamagic.net/librarys/veda/detail/2242
Status ListReverse2(LinkList L) {LinkList current, p;if (L == NULL){return NULL;}current = L->next;while (current->next != NULL){p = current->next;current->next = p->next;p->next = L->next;L->next = p;}return L; }
http://www.nowamagic.net/librarys/veda/detail/2242
Status ListReverse3(LinkList L) {LinkList newList; //新鏈表的頭結點LinkList tmp; //指向L的第一個結點,也就是要摘除的結點//參數為空或者內存分配失敗則返回NULLif (L == NULL || (newList = (LinkList)malloc(sizeof(Node))) == NULL){return NULL;}//初始化newListnewList->data = L->data;newList->next = NULL;//依次將L的第一個結點放到newList的第一個結點位置while (L->next != NULL){tmp = newList->next; //保存newList中的后續結點newList->next = L->next; //將L的第一個結點放到newList中L->next = L->next->next; //從L中摘除這個結點newList->next->next = tmp; //恢復newList中后續結點的指針}//原頭結點應該釋放掉,并返回新頭結點的指針free(L);return newList; }