#include <stdio.h>
#include <stdlib.h>
struct ListNode {
int val;
struct ListNode* next;
};
void display(struct ListNode* head)
{
struct ListNode* current = head;
while(current != NULL) {
printf("%d\n", current->val);
current = current->next;
}
}
void push(struct ListNode* head, int val)
{
struct ListNode* current = head;
while(current->next != NULL) {
current = current->next;
}
current->next = (struct ListNode*)malloc(sizeof(struct ListNode));
current->next->val = val;
current->next->next = NULL;
}
struct ListNode* traverse(struct ListNode* head)
{
if (head == NULL) {
return NULL;
}
struct ListNode* newHead = NULL;
while(head != NULL) {
struct ListNode* temp = (struct ListNode*)malloc(sizeof(struct ListNode));
temp->val = head->val;
if (newHead == NULL) {
temp->next = NULL;
} else {
temp->next = newHead;
}
newHead = temp;
head = head->next;
}
return newHead;
}
int main(int argc, char const *argv[])
{
struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode));
if (head == NULL) {
return 1;
}
head->val = 1;
head->next = NULL;
push(head, 2);
push(head, 3);
push(head, 4);
push(head, 5);
push(head, 6);
display(head);
struct ListNode* newHead = traverse(head);
printf("\n");
display(newHead);
}
当前位置:网站首页>单链表反转
单链表反转
2020-11-09 16:55:00 【洛奇_巴布亚】
版权声明
本文为[洛奇_巴布亚]所创,转载请带上原文链接,感谢
https://segmentfault.com/a/1190000037775371
边栏推荐
- Detailed explanation of ipfsapp development method of biaofen IPFs mining machine app software development software
- How important these built-in icons are to easily build a high profile application interface!
- 微服务框架 Go-Micro 集成 Nacos 实战之服务注册与发现
- 寻找性能更优秀的不可变小字典
- Explore cache configuration of Android gradle plug-in
- The internal network penetration of raspberry is built and maintained. No server is required for intranet penetration
- 电商/直播速看!双11跑赢李佳琦就看这款单品了!
- 手势切换背景,让直播带货更加身临其境
- MES系统在工厂生产管理起到9大很重要的作用
- flask图书CURD小项目
猜你喜欢
程序模拟感知机算法(梯度下降法、sklearn.linear_model中perception方法)
How important these built-in icons are to easily build a high profile application interface!
MES系统在工厂生产管理起到9大很重要的作用
MES system plays an important role in the factory production management
最新版PyCharm 2020.3 :可实现结对编程,智能文本校对等|附下载体验
CAD tutorial cad2016 installation course
5 minutes get I use GitHub's 5-year summary of these operations!
H264Nalu头部解析
Application of pull wire displacement sensor in slope cracks
Data consistency of cache
随机推荐
Exhibition cloud technology interpretation | in the face of emergencies, how does app do a good job in crash analysis and performance monitoring?
Revealing the logic of moving path selection in Summoner Canyon?
我在传统行业做数字化转型(1)预告篇
详解Git
5分钟GET我使用Github 5 年总结的这些骚操作!
5分钟GET我使用Github 5 年总结的这些骚操作!
超简单集成华为系统完整性检测,搞定设备安全防护
Solution to the failure of closing windows in Chrome browser JS
2020中国电信终端技术与标准论坛上专家解读四大热门产业
【云小课】版本管理发展史之Git+——代码托管
MES system is different from traditional management in industry application
Knowledge mapping 1.1 -- starting from NER
Kubernetes-17: kubernets package management tool -- Introduction and use of Helm
干货推荐:关于网络安全技术的专业术语,你知道多少?
Centos7下基于Pseudo-Distributed的Hadoop环境搭建
The latest version of pycharm 2020.3: pair programming, intelligent text proofreading and downloading experience
Toolkit Pro助力界面开发:缩短项目开发周期,快速实现具有现代功能区样式的GUI
函数计算进阶-IP查询工具开发
Learning notes of millet mall, day 5: ES full text search
Mobile security reinforcement helps app achieve comprehensive and effective security protection