当前位置:网站首页>206.反转链表
206.反转链表
2022-06-11 21:36:00 【爱学代码的学生】
题目描述:
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

方法1:迭代法
代码实现如下:
struct ListNode* reverseList(struct ListNode* head){
//初识条件
if(head==NULL)//条件判断
return NULL;
struct ListNode*p= head->next,*q;
head->next=NULL;//先将原头结点
//结束条件
while(p)
{
q=p->next;//记录下一个改变的结点位置
p->next=head;
head=p;
p=q;
}
return head;
}方法2:头插法
代码实现如下:
struct ListNode*cul=head;
struct ListNode*newnode=NULL;
while(cul){
struct ListNode*next=cul->next;
cul->next=newnode;
newnode=cul;
cul=next;
}
return newnode;边栏推荐
猜你喜欢
![[Part 13] source code analysis and application details of completabilefuture class [key]](/img/cf/87c60a1d46835f3f0dae9f44970de4.jpg)
[Part 13] source code analysis and application details of completabilefuture class [key]

Customer information management software

Servlet get form data

即将首发 | 业界首个零售数字化创新白皮书,解锁全链路数字化致胜秘籍

如何使用事物码 SAT 查找某个 SAPGUI 屏幕字段对应的后台存储数据库表的名称

Flutter series: detailed explanation of container layout commonly used in flutter

189. 轮转数组

Flink error: multiple tasks are started, and only one task is executed

网络连接正常但百度网页打不开显示无法访问此网站解决方案

类与对象(3)
随机推荐
B. Phoenix and Beauty
一步步把 SAP UI5 应用部署到 SAP BTP Kyma 运行环境中去
类和对象(2)
2021牛客多校5 Double Strings
JVM class loader; Parental delegation mechanism
Educational Codeforces Round 114 (Rated for Div. 2) D
Codeworks round 740 Div. 2 problem solving Report
flutter系列之:flutter中常用的container layout详解
Leetcode-98- validate binary search tree
LeetCode-104-二叉树的最大深度
How to import workflows provided on SAP API hub to sap BTP
Redis basic data type (set)
继承的所有特征
D. Game With Array
网络连接正常但百度网页打不开显示无法访问此网站解决方案
Test plans and test cases
JVM|前言介绍
字符串复制函数
Parker plunger pump pv180r1k1t1nmmc
2021-09-11 训练场补题