当前位置:网站首页>[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 .
边栏推荐
- EasyClick更新图库
- R language usarrests dataset visualization
- R语言 co2数据集 可视化
- 讲真,Kotlin 协程的挂起没那么神秘(原理篇)
- The real king of cache
- R语言AirPassengers数据集可视化
- [Jianzhi offer] interview question 44 A digit in a sequence of numbers
- R 语言 UniversalBank.csv“ 数据分析
- Xunrui CMS custom data interface PHP executable code
- Gradle Build Cache引发的Task缓存编译问题
猜你喜欢
![[resolved] -go_ out: protoc-gen-go: Plugin failed with status code 1.](/img/da/9ced1c0a9c386bc8da75dddaa443e5.png)
[resolved] -go_ out: protoc-gen-go: Plugin failed with status code 1.
Code to image converter

From perceptron to transformer, a brief history of deep learning
Solutions to Oracle system/ user locking

Easyclick fixed status log window

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

Moke 5. Service discovery -nacos

【链表中倒数第k个结点】

Résolu: peut - on avoir plus d'une colonne auto - incrémentale dans un tableau

laravel+宝塔计划任务
随机推荐
Ultrafast transformers | redesign vit with res2net idea and dynamic kernel size, surpassing mobilevit
84-我对网传&lt;52 条 SQL 语句性能优化策略&gt;的一些看法
Golang學習筆記—結構體
已解决:一個錶中可以有多個自增列嗎
[Jianzhi offer] interview question 44 A digit in a sequence of numbers
A Dynamic Near-Optimal Algorithm for Online Linear Programming
pytorch的模型保存加载和继续训练
查看苹果产品保修状态
R language CO2 dataset visualization
CVPR 2022 oral | video text pre training new SOTA, HKU and Tencent arc lab launched excuse task based on multiple-choice questions
Scheduling with Testing
71-对2010年阿里一道Oracle DBA面试题目的分析
R language Midwest dataset visualization
Visualization of R language nutrient dataset
【文末送书】火遍全网的AI给老照片上色,这里有一份详细教程!
慕课6、实现负载均衡-Ribbon
Container container runtime (2): which is better for you, yum installation or binary installation?
Cryptography series: certificate format representation of PKI X.509
农产品期货开户
Resolved: can there be multiple auto incrementing columns in a table