#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 ]所创,转载请带上原文链接,感谢
边栏推荐
- Chrome浏览器 js 关闭窗口失效解决方法
- 布客·ApacheCN 编程/后端/大数据/人工智能学习资源 2020.11
- In depth analysis of the multi-user shopping mall system from search to create a profit point
- Function calculation advanced IP query tool development
- 高质量的缺陷分析:让自己少写 bug
- 5 minutes get I use GitHub's five-year summary of these complaints!
- Git + -- Code hosting in the history of version management
- High quality defect analysis: let yourself write fewer bugs
- 低功耗蓝牙单芯片为物联网助力
- [share] interface tests how to transfer files in post request
猜你喜欢
浅谈API网关(API Gateway)如何承载API经济生态链
Which industries are suitable for enterprises to develop wechat applet?
Flink的安装和测试
我在传统行业做数字化转型(1)预告篇
Introduction to zero base little white Python
企业公司开发微信小程序适用于哪些行业?
Knowledge mapping 1.1 -- starting from NER
ABBYY FineReader 15新增编辑页面布局功能
SEO解决方案制定,如何脱离杯弓蛇影?
In depth analysis of the multi-user shopping mall system from search to create a profit point
随机推荐
SEO solution development, how to break away from the shadow of the bow?
js对象数组去重
Explore cache configuration of Android gradle plug-in
Kubernetes权限管理之RBAC (一)
深入分析商淘多用户商城系统如何从搜索着手打造盈利点
iOS下带小数点的数字键盘
flask图书CURD小项目
5 minutes get I use GitHub's 5-year summary of these operations!
High quality defect analysis: let yourself write fewer bugs
帮助企业摆脱困境,名企归乡工程师:能成功全靠有它!
ABBYY FineReader 15新增编辑页面布局功能
JS object array de duplication
布客·ApacheCN 编程/后端/大数据/人工智能学习资源 2020.11
High quality defect analysis: let yourself write fewer bugs
5分钟GET我使用Github 5 年总结的这些骚操作!
【分享】接口测试如何在post请求中传递文件
5 minutes get I use GitHub's 5-year summary of these operations!
Solve the problem that the page does not refresh after the wechat applet uses switchtab to jump
Ultra simple integration of Huawei system integrity testing, complete equipment security protection
Echart sets the spacing between columns