当前位置: 首页 > news >正文

链表分割 C语言

链表分割_牛客题霸_牛客网 (nowcoder.com)        ( 点击前面链接即可查看题目)

/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
#include <cstddef>
class Partition 
{
public:ListNode* partition(ListNode* pHead, int x){// write code hereListNode* tail1, *pHead1, *tail2, *pHead2;tail1 = pHead1 = (ListNode*)malloc(sizeof(ListNode));tail2 = pHead2 = (ListNode*)malloc(sizeof(ListNode));ListNode*  cur = pHead;while (cur) {//小于x放入链表1if (cur->val < x) {tail1->next = cur;tail1 = tail1->next;}//大于等于放入链表2else {tail2->next = cur;tail2 = tail2->next;}cur = cur->next;}tail1->next = pHead2->next;tail2->next = NULL;cur = pHead1->next;free(pHead1);free(pHead2);return cur;}
};

http://www.lryc.cn/news/409505.html

相关文章:

  • python编程,设计一个详细的软件 与SADS 相似
  • META 备受期待的 Llama 3 405B 即将发布
  • c# Math.Round()四舍五入取整数
  • 【C++BFS算法】886. 可能的二分法
  • 【MySQL】记录MySQL加载数据(LOAD DATA)
  • 6 网络
  • SQL中CASE WHEN的用法
  • CTF-Web习题:[GXYCTF2019]Ping Ping Ping
  • python+vue3+onlyoffice在线文档系统实战20240725笔记,首页开发
  • 映美精彩色相机IFrameQueueBuffer转halcon的HObject
  • 写代码对人的影响
  • Hive-基础介绍
  • 网站如何从0-1搭建部署蓝图介绍
  • 面向对象(封装)练习题 巩固一下啦!
  • 一些问题 7/28
  • 昇思MindSpore 应用学习-基于MobileNetv2的垃圾分类
  • matlab 常用数据类型的转换
  • Cocos Creator2D游戏开发(6)-飞机大战(4)-敌机产生
  • Hugo部署到Vercel踩大坑——全是XML文件?
  • 2024 暑假友谊赛-热身1
  • Nginx系列-11 HTTP消息处理流程
  • 前端知识--前端访问后端技术Ajax及框架Axios
  • 【前端/js】使用js读取本地文件(xml、二进制)内容
  • 初步入门C ++之类的概念
  • 什么是技术作家风格指南?
  • WebGIS学习——Cesium|Javascript
  • Qt,获取其他.exe文件的标准输出流的信息(printf/print的输出信息)
  • LeetCode 热题 HOT 100 (010/100)【宇宙最简单版】
  • Ubuntu24.04安装mysql-server小计,解决mysql_secure_installation时不能重置密码的问题
  • unity3d:TabView,UGUI多标签页组件,TreeView树状展开菜单