#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 ]所创,转载请带上原文链接,感谢
边栏推荐
- 从一次需求改良漫谈php文件分片上传
- How important these built-in icons are to easily build a high profile application interface!
- Kubernetes权限管理之RBAC (一)
- 2020中国电信终端技术与标准论坛上专家解读四大热门产业
- Six axes of calibration service
- 解析:C++如何实现简单的学生管理系统(源码分享)
- Talking about PHP file fragment upload from a requirement improvement
- 使用Fastai开发和部署图像分类器应用
- Revealing the logic of moving path selection in Summoner Canyon?
- 拉线式位移传感器在边坡裂缝中的作用
猜你喜欢

(3) ASP.NET Core3.1 Ocelot certification

零基础小白python入门——深入Python中的文件操作

拉线位移编码器的选择,需要精量电子的指导

Knowledge mapping 1.1 -- starting from NER

在Python中创建文字云或标签云

Introduction to zero base little white Python

H264Nalu头部解析

使用基于GAN的过采样技术提高非平衡COVID-19死亡率预测的模型准确性

拉线式位移传感器在边坡裂缝中的作用

How to choose the development of Biao fan interactive interpretation program?
随机推荐
Kubernetes-17:Kubernets包管理工具—&gt;Helm介绍与使用
5分钟GET我使用Github 5 年总结的这些骚操作!
Knowledge mapping 1.1 -- starting from NER
高性能库DPDK精简理解
CentOS view the number of CPU cores and cpuinfo analysis
如何设计并实现存储QoS?
【云小课】版本管理发展史之Git+——代码托管
Help enterprises to get rid of difficulties, famous enterprises return home Engineers: success depends on it!
js对象数组去重
Flink的安装和测试
Chrome浏览器 js 关闭窗口失效解决方法
低功耗蓝牙单芯片为物联网助力
微服务框架 Go-Micro 集成 Nacos 实战之服务注册与发现
Why does it take more and more time to develop a software?
浅谈API网关(API Gateway)如何承载API经济生态链
干货推荐:关于网络安全技术的专业术语,你知道多少?
使用Fastai开发和部署图像分类器应用
It's so easy to replace the video background with the sound and shadow
In the third stage, day16 user module jumps to SSO single sign on jsonp / CORS cross domain user login verification
Detailed explanation of ipfsapp development method of biaofen IPFs mining machine app software development software