数据结构
线性表--单链表练习题

/****************************************************************************
*
* file name: 2024-04-27_reverseLinkdemo.c
* author : tongyaqi1110@163.com
* date : 2024-04-27
* function : 实现单链表的逆序
* note : None
* CopyRight (c) 2024 tongyaqi1110@163.com Right Reseverd
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/****************************************************************************
*
* function name : reverse_list
* function :
@head
* parameter : None
*
* Return results : 返回头结点地址
* note : None
* author : tongyaqi1110@163.com
* date : 2024-04-27
* version : V1.0
* revision history : None
*
****************************************************************************/
void reverse_list(single_list *head)
{
int temp;
single_list *p = head->next; // 将链表除头节点的节点保存
head->next = NULL; // 将链表断开
single_list *tmp = NULL;
while (p != NULL)
{
tmp = p->next; // 将后面还未逆序的节点保存
// 将p插入到head的后面
p->next = head->next;
head->next = p;
// 将tmp的值赋给p
p = tmp;
}
}