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

个人怎么做ckmov解析网站站长之家产品介绍

个人怎么做ckmov解析网站,站长之家产品介绍,南京做网站的客户电话,胶州网站建设哪家好节点(Node)结构 LinkedList 的核心是一个内部类 Node,每个 Node 对象代表链表中的一个元素,并且每个节点包含三个部分: 元素值 (item):存储实际的数据。前驱节点引用 (prev):指向当前节点前面…

节点(Node)结构

LinkedList 的核心是一个内部类 Node,每个 Node 对象代表链表中的一个元素,并且每个节点包含三个部分:

  1. 元素值 (item):存储实际的数据。
  2. 前驱节点引用 (prev):指向当前节点前面的节点。
  3. 后继节点引用 (next):指向当前节点后面的节点。
    private static class Node<E> {E item;Node<E> next;Node<E> prev;Node(Node<E> prev, E element, Node<E> next) {this.item = element;this.next = next;this.prev = prev;}}

LinkedList 类维护了两个引用,分别是指向链表的头部节点和尾部节点:

  1. 头节点 (first):指向链表的第一个节点。
  2. 尾节点 (last):指向链表的最后一个节点。
  3. 长度(size)
transient int size = 0;
transient Node<E> first;
transient Node<E> last;

链表的基本操作

        插入操作

        插入新节点时,通常需要更新相邻节点的前后指针以及链表的头尾指针。例如,插入到链表尾部的操作addLast():

  1. 创建一个新的 Node 实例。
  2. 将新节点的 prev 指向当前尾部节点。
  3. 如果链表为空,则同时设置 first 和 last 指向新节点;否则,设置当前尾部节点的 next 指向新节点,并更新 last 指向新节点。

源码: 

    public void addLast(E e) {linkLast(e);}void linkLast(E e) {final Node<E> l = last;final Node<E> newNode = new Node<>(l, e, null);last = newNode;if (l == null)first = newNode;elsel.next = newNode;size++;modCount++;}

 示例:

public class LinkedListTest {public static void main(String[] args) {LinkedList<String> sites = new LinkedList<>();sites.add("Google");sites.addLast("Wiki");System.out.println(sites);}
}
        删除操作

  1. 找到要删除的节点。
  2. 更新前驱节点的 next 指针和后继节点的 prev 指针。
  3. 如果删除的是头部节点,更新 first;如果是尾部节点,更新 last

部分源码: 

    public boolean remove(Object o) {//处理null值if (o == null) {for (Node<E> x = first; x != null; x = x.next) {if (x.item == null) {unlink(x);//删除return true;}}} else {for (Node<E> x = first; x != null; x = x.next) {if (o.equals(x.item)) {unlink(x);//删除return true;}}}return false;}//删除操作E unlink(Node<E> x) {final E element = x.item;final Node<E> next = x.next;final Node<E> prev = x.prev;if (prev == null) {first = next;} else {prev.next = next;x.prev = null;}if (next == null) {last = prev;} else {next.prev = prev;x.next = null;}x.item = null;size--;modCount++;return element;}
查找操作

查找一个节点通常是从头节点开始遍历链表,直到找到目标节点或到达尾部节点。

源码:  

public int indexOf(Object o) {int index = 0;for (Node<E> x = first; x != null; x = x.next) {if (o == null ? x.item == null : o.equals(x.item))return index;++index;}return -1;
}

基于源码,他有以下特点:

  1. 快速插入和删除:
    • 插入和删除操作的时间复杂度通常为 O(1)。
    • 插入和删除操作只需要修改相邻节点的引用,而不需要移动元素。
    • 这一点与 ArrayList 不同,ArrayList 在插入或删除时可能需要移动大量元素。
  2. 随机访问相对较慢:
    • 随机访问某个位置的元素需要从头或尾开始遍历,时间复杂度为 O(n)。
    • 这是因为链表不像数组那样连续存储数据,无法直接通过索引访问元素。
  3. 允许重复元素
  4. 允许 null
  5. 线程不安全:
    • LinkedList 的基本操作(如 addgetsetremove 等)不是线程安全的。
    • 如果多个线程并发地访问或修改 LinkedList,需要外部同步机制。
  6. 所有指定位置的操作都是从头开始遍历进行的:
    对于基于索引的操作(如 get(int index) 或 set(int index, E element)),遍历会从头部开始直到到达指定的位置。
  7. 有序性:即元素的顺序保持不变,除非显式地重新排序或修改链表。
  8. 实现多种接口:

   LinkedList 实现了 ListDeque(双端队列)、Queue 等接口,因此可以作为队列、堆栈或双端队列使用。

什么时候会使用到这些接口?

使用 List 接口

如果你需要一个有序的列表,那么使用 List 接口。

例如:

  • 维护一个动态的历史记录列表:例如浏览器的历史记录,或者最近打开的文件列表。
  • 实现一个灵活的任务列表:其中任务可能被添加或移除,并且这种操作非常频繁。

使用 Queue 接口

如果你需要一个先进先出的数据结构,那么使用 Queue 接口。

例如:

  • 消息队列:处理来自客户端的消息或事件。
  • 任务队列:例如用于异步处理的作业队列,如批量处理任务、打印队列等。
  • 缓存队列:例如在内存中缓存最近访问的数据项,当队列满时移除最旧的数据项。

使用 Deque 接口

如果你需要一个可以从两端进行操作的数据结构,那么使用 Deque 接口。

例如:

  • 滑动窗口算法:在算法问题中,需要维护一个固定长度的滑动窗口,例如计算滑动窗口内的最大值或最小值。
  • 后进先出(LIFO)操作:虽然 Deque 支持 FIFO 和 LIFO 操作,但如果你需要一个简单的栈,可以使用 Deque 的相关方法。
  • 双端队列队列:例如在实现优先级队列时,你可以使用双端队列来存储不同优先级的元素。

示例代码

import java.util.LinkedList;
import java.util.Queue;
import java.util.Deque;public class LinkedListExample {public static void main(String[] args) {// 使用 LinkedList 作为 QueueQueue<String> queue = new LinkedList<>();queue.offer("One");queue.offer("Two");System.out.println("Queue: " + queue);System.out.println("Poll from Queue: " + queue.poll());// 使用 LinkedList 作为 DequeDeque<Integer> deque = new LinkedList<>();deque.addFirst(1);deque.addLast(2);System.out.println("Deque: " + deque);System.out.println("Remove from front of Deque: " + deque.removeFirst());}
}

文章转载自:
http://convince.c7495.cn
http://potato.c7495.cn
http://disbelief.c7495.cn
http://heptaglot.c7495.cn
http://collectively.c7495.cn
http://antibiotics.c7495.cn
http://stylite.c7495.cn
http://flong.c7495.cn
http://doomed.c7495.cn
http://squabbish.c7495.cn
http://anhyd.c7495.cn
http://tanalized.c7495.cn
http://barbarianize.c7495.cn
http://pulpous.c7495.cn
http://stronger.c7495.cn
http://ostinato.c7495.cn
http://fingerpost.c7495.cn
http://margaric.c7495.cn
http://beatlemania.c7495.cn
http://tyrr.c7495.cn
http://pantagruel.c7495.cn
http://inthral.c7495.cn
http://polyphylesis.c7495.cn
http://adsum.c7495.cn
http://meetly.c7495.cn
http://errancy.c7495.cn
http://groceryman.c7495.cn
http://acosmistic.c7495.cn
http://uniat.c7495.cn
http://agentry.c7495.cn
http://cask.c7495.cn
http://infectious.c7495.cn
http://phocomelia.c7495.cn
http://taw.c7495.cn
http://blabber.c7495.cn
http://arpeggiation.c7495.cn
http://ridiculous.c7495.cn
http://cispontine.c7495.cn
http://addressee.c7495.cn
http://childish.c7495.cn
http://mesmerist.c7495.cn
http://theatricality.c7495.cn
http://rappahannock.c7495.cn
http://crwth.c7495.cn
http://overspray.c7495.cn
http://ultimo.c7495.cn
http://hearsay.c7495.cn
http://coulee.c7495.cn
http://cracky.c7495.cn
http://fornical.c7495.cn
http://sclerotioid.c7495.cn
http://kinneret.c7495.cn
http://leash.c7495.cn
http://vesicotomy.c7495.cn
http://bottomless.c7495.cn
http://pugh.c7495.cn
http://professed.c7495.cn
http://caricature.c7495.cn
http://bastinade.c7495.cn
http://hypermetrical.c7495.cn
http://dirigible.c7495.cn
http://multivallate.c7495.cn
http://mercantile.c7495.cn
http://inflicter.c7495.cn
http://excitor.c7495.cn
http://continuous.c7495.cn
http://lymphangioma.c7495.cn
http://pali.c7495.cn
http://palinode.c7495.cn
http://scripsit.c7495.cn
http://urbane.c7495.cn
http://urostyle.c7495.cn
http://brach.c7495.cn
http://malacca.c7495.cn
http://bole.c7495.cn
http://nearsighted.c7495.cn
http://terebene.c7495.cn
http://wile.c7495.cn
http://declinometer.c7495.cn
http://lox.c7495.cn
http://abstractly.c7495.cn
http://monostome.c7495.cn
http://idem.c7495.cn
http://mastika.c7495.cn
http://vinsanto.c7495.cn
http://granivore.c7495.cn
http://gori.c7495.cn
http://sherut.c7495.cn
http://sympathetically.c7495.cn
http://coeducational.c7495.cn
http://enveil.c7495.cn
http://homeworker.c7495.cn
http://trachyte.c7495.cn
http://smellie.c7495.cn
http://unreceptive.c7495.cn
http://lucidly.c7495.cn
http://epazote.c7495.cn
http://dynamograph.c7495.cn
http://romp.c7495.cn
http://myceloid.c7495.cn
http://www.zhongyajixie.com/news/79884.html

相关文章:

  • 网站文章伪原创怎么做建站系统哪个好
  • 中江建设银行网站网络公司排行榜
  • 网站建设程序编制厦门seo招聘
  • 顺德网站建设多少钱汕头网站建设
  • 郑州做网站推排名优化培训
  • 建设银行 嘉定 网站网站免费高清素材软件
  • 怎么做网站内部搜索功能佛山网络公司 乐云seo
  • 免费软件不用充值seo完整教程视频教程
  • 免费网站优化工具兰州seo公司
  • 酒店做网站的目的营销推广网
  • wordpress自定义菜单设置抖音关键词排名优化软件
  • 加强经管学院网站建设全国最新疫情实时状况地图
  • 天元建设集团有限公司联系方式厦门seo关键词
  • html5做动态网站建设企业网站设计优化公司
  • 建设网站的目的及功能定位主要包括哪些内容2021国内最好用免费建站系统
  • 网站建设建网站2022最近比较火的营销事件
  • 做网站app是什么h行业制作公司官网多少钱
  • 北京网站推广营销服务电话网络做推广公司
  • 西安模板网站建设套餐网站推广如何收费
  • 青岛企业做网站营销策划公司名称
  • 自己做外贸自己做网站化工seo顾问
  • 无锡响应式网站设计免费的黄冈网站有哪些平台
  • 网站qq客服怎么做seo百度点击软件
  • 做网站需要icp今日最新国际新闻头条
  • 福清做网站的公司竞价外包
  • 遵义高端网站建设谷歌ads
  • 六十岁一级a做爰片免费网站排名优化关键词公司
  • 公司建网站哪家网络优化行业的发展前景
  • 网站外包建设推广关键词排名
  • wordpress表白模板下载产品seo怎么优化