#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);
}
当前位置:网站首页>Single linked list inversion
Single linked list inversion
2020-11-09 16:55:00 【Rocky_ Papua 】
版权声明
本文为[Rocky_ Papua ]所创,转载请带上原文链接,感谢
边栏推荐
- 菜鸟福音,28本书籍循序渐进让你成为大牛!(附学习大纲一份)
- Custom indoor map online tool
- 解析:C++如何实现简单的学生管理系统(源码分享)
- How about Tencent cloud amd cloud server?
- 布客·ApacheCN 编程/后端/大数据/人工智能学习资源 2020.11
- In depth analysis of the multi-user shopping mall system from search to create a profit point
- 第三阶段 Day19 用户回显 封装Cookie 商品远程调用 购物车模块 CRUD操作
- 函数计算进阶-IP查询工具开发
- The basic principle of MRAM
- EasyExcel根据筛选列导出(中间不空列,顺序可调整)
猜你喜欢
SEO solution development, how to break away from the shadow of the bow?
【分享】接口测试如何在post请求中传递文件
从一次需求改良漫谈php文件分片上传
Do you think it's easy to learn programming? In fact, it's hard! Do you think it's hard to learn programming? In fact, it's very simple!
Data consistency of cache
5 minutes get I use GitHub's five-year summary of these complaints!
在Python中创建文字云或标签云
Application of pull wire displacement sensor in slope cracks
第三阶段 Day20 购物车模块实现 添加拦截器 添加用户权限校检 实现订单模块
Introduction to zero base little white Python
随机推荐
The basic principle of MRAM
High quality defect analysis: let yourself write fewer bugs
Solution to the failure of closing windows in Chrome browser JS
Custom indoor map online tool
Full stack technology experience tells you: how much does it cost to develop a mall small program?
Ultra simple integration of Huawei system integrity testing, complete equipment security protection
Source code analysis of serilog -- implementation of sink
CentOS view the number of CPU cores and cpuinfo analysis
Set two ways of background image, and solve the mobile phone background image highly adaptive problem
SEO solution development, how to break away from the shadow of the bow?
How to use Camtasia to make dynamic animation scene?
用微信表情翻译表白,程序员的小浪漫,赶紧Get起来!
EasyExcel根据筛选列导出(中间不空列,顺序可调整)
Git + -- Code hosting in the history of version management
高质量的缺陷分析:让自己少写 bug
高质量的缺陷分析:让自己少写 bug
echart 设置柱子之间的间距
Detailed explanation of ipfsapp development method of biaofen IPFs mining machine app software development software
Ubuntu18.04 NAT模式下配置静态IP地址 -2020.11.09
Using fastai to develop and deploy image classifier application