曲周专业做网站上海展陈设计公司有哪些
2026/3/29 12:31:04 网站建设 项目流程
曲周专业做网站,上海展陈设计公司有哪些,一个做网站的公司年收入,网站链接导出一、本周核心学习内容 链表基础知识复习 单链表结构回顾#xff1a;复习了链表节点的基本定义、链表的创建、插入、删除和遍历操作 链表与数组对比#xff1a;重新梳理了链表在动态内存分配、插入删除效率等方面的优势 常见链表操作#xff1a;包括反转链表、合并有序链表、…一、本周核心学习内容链表基础知识复习单链表结构回顾复习了链表节点的基本定义、链表的创建、插入、删除和遍历操作链表与数组对比重新梳理了链表在动态内存分配、插入删除效率等方面的优势常见链表操作包括反转链表、合并有序链表、检测环等基础算法双指针技术深入掌握本周重点学习了三种双指针应用场景快慢指针应用// 1. 检测链表环structListNode{intval;structListNode*next;};inthasCycle(structListNode*head){if(headNULL||head-nextNULL){return0;}structListNode*slowhead;structListNode*fasthead;while(fast!NULLfast-next!NULL){slowslow-next;// 慢指针走一步fastfast-next-next;// 快指针走两步if(slowfast){// 两指针相遇说明有环return1;}}return0;// 无环}左右指针应用// 2. 反转链表双指针实现structListNode*reverseList(structListNode*head){structListNode*prevNULL;structListNode*currhead;while(curr!NULL){structListNode*nextTempcurr-next;// 暂存下一个节点curr-nextprev;// 反转指针方向prevcurr;// 前指针后移currnextTemp;// 当前指针后移}returnprev;// 新的头节点}前后指针应用// 3. 删除链表倒数第N个节点structListNode*removeNthFromEnd(structListNode*head,intn){structListNodedummy{0,head};// 虚拟头节点简化边界处理structListNode*firstdummy;structListNode*seconddummy;// 让first指针先走n1步for(inti0;in;i){firstfirst-next;}// 两个指针同步移动直到first到达末尾while(first!NULL){firstfirst-next;secondsecond-next;}// 删除目标节点structListNode*toDeletesecond-next;second-nextsecond-next-next;returndummy.next;}快慢指针找链表中点// 找到链表的中间节点structListNode*findMiddle(structListNode*head){if(headNULL||head-nextNULL){returnhead;}structListNode*slowhead;structListNode*fasthead;// 快指针每次走两步慢指针每次走一步while(fast!NULLfast-next!NULL){slowslow-next;fastfast-next-next;}returnslow;// 当快指针到达末尾时慢指针刚好在中间}双指针判断回文链表// 判断链表是否为回文结构intisPalindrome(structListNode*head){if(headNULL||head-nextNULL){return1;}// 步骤1找到中点structListNode*slowhead;structListNode*fasthead;while(fast-next!NULLfast-next-next!NULL){slowslow-next;fastfast-next-next;}// 步骤2反转后半部分链表structListNode*secondHalfreverseList(slow-next);// 步骤3比较前后两部分structListNode*p1head;structListNode*p2secondHalf;intresult1;while(resultp2!NULL){if(p1-val!p2-val){result0;}p1p1-next;p2p2-next;}// 步骤4恢复原链表可选slow-nextreverseList(secondHalf);returnresult;}双指针解决两数相加// 两个链表表示的非负整数相加structListNode*addTwoNumbers(structListNode*l1,structListNode*l2){structListNodedummy{0,NULL};structListNode*currdummy;intcarry0;// 进位while(l1!NULL||l2!NULL||carry!0){intsumcarry;if(l1!NULL){suml1-val;l1l1-next;}if(l2!NULL){suml2-val;l2l2-next;}carrysum/10;// 计算进位curr-next(structListNode*)malloc(sizeof(structListNode));curr-next-valsum%10;// 当前位结果curr-next-nextNULL;currcurr-next;}returndummy.next;}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询