news 2026/6/26 17:01:57

实现链表分割

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
实现链表分割

实现链表分割

/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */structListNode*partition(structListNode*head,intx){structListNode*list1,*head1,*list2,*head2;list1=head1=(structListNode*)malloc(sizeof(structListNode));list2=head2=(structListNode*)malloc(sizeof(structListNode));structListNode*cur=head;while(cur){if(cur->val<x){list1->next=cur;list1=list1->next;}else{list2->next=cur;list2=list2->next;}cur=cur->next;}list2->next=NULL;list1->next=head2->next;head=head1->next;free(head1);free(head2);returnhead;}

/**

  • Definition for singly-linked list.
  • struct ListNode {
  • int val;
  • struct ListNode *next;
  • };
    /
    struct ListNode
    partition(struct ListNode* head, int x)
    {
    struct ListNode* list1,head1,list2,head2;
    list1=head1=(struct ListNode
    )malloc(sizeof(struct ListNode));
    list2=head2=(struct ListNode
    )malloc(sizeof(struct ListNode));
    struct ListNode
    cur=head;
    while(cur)
    {
    if(cur->val<x)
    {
    list1->next=cur;
    list1=list1->next;
    }
    else
    {
    list2->next=cur;
    list2=list2->next;
    }
    cur=cur->next;
    }
    list2->next=NULL;
    list1->next=head2->next;
    head=head1->next;
    free(head1);
    free(head2);
    return head;
    }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/26 16:55:03

树莓派系统安装全攻略:从版本选择到实战避坑指南

1. 从零开始&#xff1a;为你的树莓派选择操作系统如果你刚拿到一块树莓派&#xff0c;或者准备用它开启一个新项目&#xff0c;第一件也是最重要的事&#xff0c;就是给它安装一个操作系统。这听起来可能有点技术门槛&#xff0c;但别担心&#xff0c;整个过程其实比给电脑重装…

作者头像 李华
网站建设 2026/6/26 16:53:24

如何选择合适的嵌入式核心板产品?

嵌入式产品的设计是一个复杂的系统工程&#xff0c;从硬件到应用软件&#xff0c;再到底层驱动&#xff0c;一个好的产品往往需要考虑诸多因素。那么&#xff0c;工程师该如何选择一款合适的核心板产品呢&#xff1f;今天我们就来深入探讨一下。1. 技术规格技术规格无疑是首要考…

作者头像 李华
网站建设 2026/6/26 16:44:16

Berge超图广义Turán数:从极值图论到超图计数的核心理论与方法

1. 项目概述&#xff1a;当极值图论遇上超图计数如果你对图论有一定了解&#xff0c;大概率听说过Turn定理——这个极值图论领域的基石&#xff0c;探讨的是在一个n个顶点的图中&#xff0c;在不包含特定子图&#xff08;比如完全图Kr&#xff09;的前提下&#xff0c;最多能有…

作者头像 李华
网站建设 2026/6/26 16:43:38

智慧养殖4G物联网方案:TCP协议与低功耗设计

1. 智慧养殖盒子4G接入TCP云服务全解析作为一名在物联网领域摸爬滚打多年的工程师&#xff0c;今天想和大家分享一个非常实用的开源项目——智慧养殖盒子的4G接入TCP云服务实现方案。这个方案特别适合需要远程监控养殖场环境参数的场景&#xff0c;比如温度、湿度、有害气体浓度…

作者头像 李华