大庆建设网站首页优化大师官方下载

news/2025/9/30 15:52:23/文章来源:
大庆建设网站首页,优化大师官方下载,wordpress获取广告js,网站建设颜色代码表1.链表的概念 对于顺序存储的结构最大的缺点就是插入和排序的时候需要移动大量的元素#xff0c;所以链表的出生由此而来 先上代码#xff1a; // 链表 public class LinkedListT extends Comparable {// 结点类class Node {T ele; // 当前结点上的元素内容Node ne…1.链表的概念 对于顺序存储的结构最大的缺点就是插入和排序的时候需要移动大量的元素所以链表的出生由此而来 先上代码 // 链表 public class LinkedListT extends Comparable {// 结点类class Node {T ele; // 当前结点上的元素内容Node next; // 指向下个结点的索引public Node(T ele) {this.ele ele;}Overridepublic String toString() {return ele.toString();}}// 头结点private Node head;// 链表中实际存放结点的个数private int size;// 判断链表是否为空public boolean isEmpty() {return head null;}// 获取链表中结点的个数public int getSize() {return this.size;}public void addHead(T ele) {this.add(0, ele);}public void addTail(T ele) {this.add(this.size, ele);}// 在指定位置添加结点, 关键点: 找到待插入位置的前一个结点public void add(int index, T ele) {if (index 0 || index this.size) {throw new IllegalArgumentException(index is invalid!);}Node node new Node(ele);// 给链表增加一个虚拟头结点, 解决在链表的头部添加时的特殊处理Node dummyHead new Node(null);dummyHead.next head;Node prev dummyHead;for (int i 0; i index; i) {prev prev.next;}node.next prev.next;prev.next node;// 更新头结点head dummyHead.next;this.size;}//根据索引找对应的元素public T get(int index){if(index0||indexthis.size){return null;}Node curhead;for (int i 0; i index; i) {curcur.next;}return cur.ele;} //获取头节点的元素public T getFirst(){return get(0);}//获取尾结点的元素public T getLast(){return get(this.size-1);}//判断是否包含该元素public boolean contain(T ele){Node curhead;for (int i 0; i this.size; i) {if(cur.ele.compareTo(ele)0){return true;}curcur.next;}return false;}//将链表中的某个元素进行替换public void set(T ele,int index) {if(index0||indexthis.size){}Node curhead;for (int i 0; i index; i) {curcur.next;}cur.eleele;}//将链表中的元素进行删除public void delete(int index) {if (index 0 || index this.size) {}//无虚拟头结点 // if (index 0) { // Node delnode head; // head delnode.next; // delnode.next null; // this.size--; // } else { // Node pre head; // Node cur pre.next; // for (int i 1; i index; i) { // pre pre.next; // curcur.next; // } // Node delnode cur; // pre.next delnode.next; // delnode.next null; // this.size--; // cur cur.next;//有虚拟头节点Node dummyNodenew Node(null);dummyNode.nexthead;Node predummyNode;Node curpre.next;for (int i 0; i index; i) {prepre.next;curcur.next;}Node delnode cur;pre.next delnode.next;delnode.next null;this.size--;cur cur.next;}Overridepublic String toString() {//IO流StringBuilder sb new StringBuilder();// 头结点不能动Node cur head;while (cur ! null) {sb.append(cur --);cur cur.next;}return sb.toString();} } 1.链表的定义 链表是由一个个结点组成的每个结点之间通过链接关系串联起来的每个结点都有一个前驱、一个后继最后一个结点的后继结点为空节点 由链接关系A-B组织起来的两个结点B称为A的后继结点A被称为B的前驱结点链表分为单向链表、双向链表、循环链表等 2.链表结点的定义 由于该类继承了Comparable,所以该类中的元素具有了比较性ele代表的是数据域可以是任意的类型由编码的人自行指定next代表指针域指向后继结点的地址 3.虚拟头结点 为了方便对链表的头结点执行操作往往会建立一个虚拟头结点这个结点上也不存储数据也就是ele字段永远为空或者是为一个特殊的标识 ListNode dummyNodenew ListNode(head,-1);//后继结点为头结点默认值为-1 2.链表的遍历 1.遍历的含义 遍历就是从链表头结点开始对所有的结点一次访问的过程 2.动画演示 虚拟头节点head用-1进行标识tmp代表当前遍历到的结点其中tmp后的数字代表链表结点的索引 3.链表结点的索引 1.索引的含义 链表结点的索引就是给定一个链表头和一个下标index,通过下标获取到链表第index个元素 2.动画演示 3.代码演示 //根据索引找对应的元素public T get(int index){if(index0||indexthis.size){return null;}Node curhead;for (int i 0; i index; i) {curcur.next;}return cur.ele;} 4.链表结点的插入 1.插入的含义 给定一个链表头和一个位置index(index0)和一个值ele生成一个值为ele的结点并且将它插入到链表第index之后的位置 2.动画演示 3.演示代码 // 在指定位置添加结点, 关键点: 找到待插入位置的前一个结点public void add(int index, T ele) {if (index 0 || index this.size) {throw new IllegalArgumentException(index is invalid!);}Node node new Node(ele);// 给链表增加一个虚拟头结点, 解决在链表的头部添加时的特殊处理Node dummyHead new Node(null);dummyHead.next head;Node prev dummyHead;for (int i 0; i index; i) {prev prev.next;}node.next prev.next;prev.next node;// 更新头结点head dummyHead.next;this.size;} 5.链表结点的删除 1.删除的含义 给定一个链表头和一个位置index(index1)将位置index的结点删除并且返回被删除的结点由于第一个结点是虚拟头结点所以我们要从索引为1的位置开始 2.动画演示 3.代码演示 //将链表中的元素进行删除public void delete(int index) {if (index 0 || index this.size) {}//无虚拟头结点 // if (index 0) { // Node delnode head; // head delnode.next; // delnode.next null; // this.size--; // } else { // Node pre head; // Node cur pre.next; // for (int i 1; i index; i) { // pre pre.next; // curcur.next; // } // Node delnode cur; // pre.next delnode.next; // delnode.next null; // this.size--; // cur cur.next;//有虚拟头节点Node dummyNodenew Node(null);dummyNode.nexthead;Node predummyNode;Node curpre.next;for (int i 0; i index; i) {prepre.next;curcur.next;}Node delnode cur;pre.next delnode.next;delnode.next null;this.size--;cur cur.next;}6.链表结点的查找 1.查找的含义 查找的含义就是给定一个值通过遍历链表找到链表值和给定相等的那个结点 2.动画演示 3.代码演示 //根据索引找对应的元素public T get(int index){if(index0||indexthis.size){return null;}Node curhead;for (int i 0; i index; i) {curcur.next;}return cur.ele;} 7.链表结点的修改 1.修改的含义 给定一个链表头一个位置index(index1)和一个值ele将位置index的结点值修改为ele 2.代码演示 //将链表中的某个元素进行替换public void set(T ele,int index) {if(index0||indexthis.size){}Node curhead;for (int i 0; i index; i) {curcur.next;}cur.eleele;} leetcode题单 返回倒数第k个节点 // 双指针public int kthToLast(ListNode head, int k) {ListNode fast head;ListNode slow head;// 让快指针先走k步for (int i 0 ; i k ; i) {fast fast.next;}// 再让快指针和慢指针同时移动// 当快指针走到链表结尾时// 慢指针所指向的节点就是目标节点while (fast ! null) {fast fast.next;slow slow.next;}return slow.val;} 删除链表的倒数第N个节点 //利用双指针public ListNode removeNthFromEnd(ListNode head, int n) {if(headnull||n0){return head;}ListNode dummyNodenew ListNode(0,head);ListNode slowdummyNode;ListNode fastdummyNode;for (int i 0; i n1; i) {fastfast.next;}while(fast!null){slowslow.next;fastfast.next;}slow.nextslow.next.next;return dummyNode.next;} 反转链表 public ListNode reverseList(ListNode head) {if(headnull||head.nextnull){return head;}ListNode resNodereverseList(head.next);head.next.nexthead;head.nextnull;return resNode;}public ListNode reverseList(ListNode head) {//如果头结点为空或者是头结点的后继节点为空的话直接返回头结点if(headnull ||head.nextnull){return head;}//定义指针ListNode curhead;ListNode tempcur.next;ListNode prenull;while(cur!null){tempcur.next;cur.nextpre;precur;curtemp;}return pre;} 删除链表中的节点 public void deleteNode(ListNode node) {node.valnode.next.val;node.nextnode.next.next;} 两两交换链表中的节点 //方法一public ListNode swapPairs(ListNode head) {if(headnull||head.nextnull){return head;}ListNode lefthead;ListNode rightleft.next;ListNode newNodeswapPairs(right.next);left.nextnewNode;right.nextleft;return right;}//方法二public ListNode swapPairs(ListNode head) {if(headnull||head.nextnull){return head;}ListNode rhead;for (int i 0; i 2; i) {if(rnull){return head;}rr.next;}ListNode nodereverse(head,r);head.nextswapPairs(r);return node;}public ListNode reverse(ListNode head,ListNode right){ListNode prenull,curNodehead,nextnull;while(curNode!right){nextcurNode.next;curNode.nextpre;precurNode;curNodenext;}return pre; }//方法三public ListNode swapPairs(ListNode head) {//对入参进行判断if(headnull||head.nextnull){return head;}ListNode dummyHeadnew ListNode(Integer.MIN_VALUE);dummyHead.nexthead;ListNode predummyHead;ListNode curpre.next;ListNode nextcur.next;while(cur!nullnext!null){cur.nextnext.next;next.nextcur;pre.nextnext;precur;curpre.next;nextcurnull?null:cur.next;}return dummyHead.next ;}//方法四public ListNode swapPairs(ListNode head) {if(headnull||head.nextnull){return head;}//将头结点的后继点设置为resListNode res head.next;//将res.next和res.next.next进行交换head.next swapPairs(res.next);//原先的res与头结点相连接res.next head;//返回对应的resreturn res; }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923027.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2025 年电动窗帘厂家推荐榜单:聚焦国内优质企业定制实力与口碑,为采购者提供最新选择参考电动窗帘系统/电机/轨道/配件/智能电动窗帘厂家推荐

当下智能家居行业蓬勃发展,电动窗帘作为提升居住与办公舒适度的关键产品,市场需求持续攀升。然而,行业乱象却给采购者带来诸多困扰:部分品牌原材料选用不规范,劣质材料导致产品稳定性差、使用寿命短;定制服务能力…

网站推广的技巧wordpress 代码压缩

1.set和map存在的意义 (1)set和map的底层都是二叉搜索树,可以达到快速排序(当我们按照迭代器的顺序来遍历set和map,其实是按照中序来遍历的,是排过序的)、去重、搜索的目的。 (2&a…

淘宝首页网站怎么做手机短视频制作软件app

目录 一,题目 二,思路 三,代码 一,题目 输入 共2行,第1行是被减数a,第2行是减数b(a > b)。每个大整数不超过200位,不会有多余的前导零。 输出 一行,即所求的差。 样例输入1…

网站建设公司业务望京做网站

目录频率域滤波基础频率域的其他特性频率域滤波基础知识频率域滤波步骤小结空间域和频率域滤波之间的对应关系频率域滤波基础 频率域的其他特性 频率域中的滤波过程如下: 首先修改傅里叶变换以在到特定目的然后计算IDFT,返回到空间域 # 频率域中的其…

专业微网站开发wordpress 用户登陆后跳转到首页

register_shutdown_function注册一个会在php中止时执行的函数,注册一个 callback ,它会在脚本执行完成或者 exit() 后被调用。error_get_last获取最后发生的错误,包含type(错误类型),message(错误消息),file(发生错误所…

java类加载内存分析

java类加载内存分析加载内存分析 1.加载到内存(方法区(即特殊的堆)存放原始类,加载完成后会产生一个类对应java.lang.class对象代表不同的类存放到堆中,最后在栈中开始main()链接 2.链接,连接结束后静态变量默认…

Vue3 使用注意事项

1.script-setup语法糖下// 获取 emit,注意需要直接在setup范围下,放在具体方法里,可能会因作用域导致获取不到defineEmitsconst emit = defineEmits([quanping-comp]);

ClickHouse ReplacingMergeTree 去重陷阱:为什么你的 FINAL 查询无效? - 若

问题背景 在使用 ClickHouse 的 ReplacingMergeTree 引擎时,很多开发者会遇到一个困惑:明明使用了 FINAL 关键字,查询结果却仍然包含重复数据。比如这样的情况:数据库表err := db.Table(model.BlockTaskTableName)…

js中?? 和 || 的区别详解

?? 和 || 的区别详解 在 JavaScript/TypeScript 中,??(空值合并运算符)和 ||(逻辑或运算符)都用于提供默认值,但它们在处理不同值时有关键区别。 核心区别运算符 名称 触发条件 处理假值的方式?? 空值合并…

微信机器人API接口| 个人开发者必备

微信机器人API接口| 个人开发者必备 微信二次开发个人号api个人微信机器人开发api接口,微信个人号开发API在线接待更高效 在线沟通更快速、更有趣 语音回复 通过电脑端语音回复客户,提高效率 文件传输 支持文字、图片…

直击现场! “ 直通乌镇 ”开源赛复赛收官,OpenCSG担任评委,十强藏着哪些产业机会?

2025年9月16日,备受瞩目的“直通乌镇”全球互联网开源模型应用赛复赛在杭州圆满落幕。浙江省经济和信息化厅相关领导及各界专家、参赛团队代表齐聚一堂,共同见证了这一激动人心的时刻。值得关注的是,今年大赛首次设…

Python 列表生成式、字典生成式与生成器表达式

1. 列表生成式 (List Comprehension) 语法:[expression for item in iterable if condition] 示例:1.基本示例 # 创建平方数列表 squares = [x**2 for x in range(5)] print(squares) # [0, 1, 4, 9, 16]# 创建偶数…

java 解析json字符串,获取特定的字段值,JsonObject

java 解析json字符串,获取特定的字段值,JsonObjectjava 解析json字符串,获取特定的字段值package com.example.core.mydemo.java3;import com.google.gson.Gson; import com.google.gson.JsonObject; import com.go…

python 批量提取txt数据中的值写入csv

我有一堆雨滴谱txt数据,第一行是时间就是2024-05-10 10:21:00这样的格式,第二行是值,第三行是空格,然后第四行又是2024-05-10 10:21:00,第五行是值,第六行是空格,这样循环往复。给我写一个批量提取这些值的pyth…

【读书笔记】架构整洁之道 P5-2 软件架构 - 教程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

嘉兴 企业网站 哪家厦门网站建设模板

效率工具 推荐一个程序员的常用工具网站,效率加倍嘎嘎好用:程序员常用工具 云服务器 云服务器限时免费领:轻量服务器2核4G腾讯云:2核2G4M云服务器新老同享99元/年,续费同价阿里云:2核2G3M的ECS服务器只需99…

网站建设后台 手工上传网页图片显示不出来打叉

介绍: JavaScript是一种基于对象和事件驱动的编程语言,在Web开发中占据着重要的地位。随着前端技术的不断发展,出现了一系列的框架和库,Vue和React是其中较为知名的两个。 Vue是一个轻量级的JavaScript框架,由尤雨溪…

金华市金东区建设局网站上海软件外包公司有哪些

1.概述 QwtPlotMarker类是Qwt绘图库中用于在图表上绘制标记的类。标记可以是垂直或水平线、直线、文本或箭头等。它可用于标记某个特定的位置、绘制参考线或注释信息。 以下是类继承关系图: 2.常用方法 设置标记的坐标。传入x和y坐标值,标记将被放置在…

怎么做网站教程html文本文档wordpress 首页 缩略图

目录 一、网络文件 1.1.存储类型 1.2.FTP 文件传输协议 1.3.传输模式 二、内网搭建yum仓库 一、网络文件 1.1.存储类型 直连式存储:Direct-Attached Storage,简称DAS 存储区域网络:Storage Area Network,简称SAN&#xff0…

回忆中学的函数

这篇文章,带你一次性回顾中学时代里的那些函数。如果对初中、高中的函数还记忆模糊,建议往下翻一翻。 目录一、函数的意义要素特征二、初阶函数1. 一次函数函数特征应用示例2. 反比例函数函数特征应用示例3. 二次函数…