当前位置:网站首页>[cm11 linked list splitting]
[cm11 linked list splitting]
2022-06-22 21:06:00 【Cat star people who love Durian】
List of articles
One 、 Title Description
The head pointer of an existing linked list ListNode pHead, Give a certain value x, Write a piece of code that will all be less than x The nodes of are arranged before the other nodes , And the original data order cannot be changed , Returns the head pointer of the rearranged linked list .
Two 、 Provide easy to read code diagram

3、 ... and 、 Title code
Tips : Pay attention to the dead cycle , Must put bigTail->next Set up NULL
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/
class Partition {
public:
ListNode* partition(ListNode* pHead, int x) {
ListNode* smallHead=(ListNode*)malloc(sizeof( ListNode));
smallHead->next=NULL;
ListNode* bigHead=(ListNode*)malloc(sizeof( ListNode));
bigHead->next=NULL;
ListNode* cur,*bigTail,*smallTail;
cur=pHead;
smallTail=smallHead;
bigTail=bigHead;
while(cur)
{
if(cur->val<x)
{
smallTail->next=cur;
smallTail=smallTail->next;
}
else
{
bigTail->next=cur;
bigTail=bigTail->next;
}
cur=cur->next;
}
bigTail->next=NULL;
smallTail->next=bigHead->next;
ListNode* newHead=smallHead->next;
free(smallHead);
free(bigHead);
return newHead;
}
};
The above is the whole content of this article , If there are mistakes in the article or something you don't understand , Communicate more with meow bloggers . Learn from each other and make progress . If this article helps you , Can give meow bloggers a concern , Your support is my biggest motivation .
边栏推荐
- 86-给参加&lt;SQL写法与改写培训&gt;的学员补充一个二手案例
- MYSQL 几个常用命令使用
- R语言penguins数据集可视化
- [proteus simulation] H-bridge drive DC motor composed of triode + key forward and reverse control
- C语言中int和char的对应关系
- 如何使用Feign构造多参数的请求
- Flutter System Architecture(Flutter系统架构图)
- 【876. 链表的中间结点】
- Ultrafast transformers | redesign vit with res2net idea and dynamic kernel size, surpassing mobilevit
- R语言midwest数据集可视化
猜你喜欢

53页智慧校园智能化系统设计方案(附下载)

Software testing - Test Case Design & detailed explanation of test classification

Raspberry pie environment settings

2022团体程序设计天梯赛L1

uniapp小程序商城开发thinkphp6积分商城、团购、秒杀 封装APP

底部菜单添加的链接无法跳转到二级页面的问题

访问成功但抛出异常:Could not find acceptable representation

Easyclick fixed status log window

让知识付费系统视频支持M3U8格式播放的方法

R 语言USArrests 数据集可视化
随机推荐
70-根因分析-oracle数据库突发性能问题,谁来背这个锅
Is the brokerage account of qiniu delivery safe? Is the brokerage account provided by qiniu true?
R语言penguins数据集可视化
使用Charles抓包
[proteus simulation] H-bridge drive DC motor composed of triode + key forward and reverse control
Introduction of neural networks for Intelligent Computing (Hopfield network DHNN, CHNN)
Huawei cloud releases Latin American Internet strategy
How to use feign to construct multi parameter requests
[observation] innovation in the software industry has entered a "new cycle". How can we make a new start in the changing situation?
Feign常见问题总结
Lora technology -- Lora signal changes from data to Lora spread spectrum signal, and then from RF signal to data through demodulation
如何计算 R 中的基尼系数(附示例)
SwiftUI如何模拟视图发光增大的动画效果
R 语言 UniversalBank.csv“ 数据分析
C语言中int和char的对应关系
[Jianzhi offer] interview question 44 A digit in a sequence of numbers
农产品期货开户
Golang學習筆記—結構體
A detailed solution to mysql8.0 forgetting password
Cryptography series: certificate format representation of PKI X.509