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; }