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

大淘客平台怎么做分销网站华联股份股票

大淘客平台怎么做分销网站,华联股份股票,卓博招聘人才网,上海招标网站链表 链表的概念 链表是一种物理存储结构上非连续的存储结构,数据元素的逻辑顺序是通过链表中的引用链接次序实现的。 通俗来说,相比较于顺序表(物理上连续,逻辑上也连续),链表物理上不一定连续。 链表是…

链表

链表的概念

链表是一种物理存储结构上非连续的存储结构,数据元素的逻辑顺序是通过链表中的引用链接次序实现的。

通俗来说,相比较于顺序表(物理上连续,逻辑上也连续),链表物理上不一定连续。

链表是由一个一个节点组织起来的,组织起来的整体就叫做链表。

链表的结构非常多样,

1.单向或双向

2.带头或不带头

3.循环或非循环

以上的链表结构可以组成八种链表。

在Java集合框架中的LinkedList底层实现的是无头双向循环链表

LinkedList模拟实现

1.创建一个无头双向链表,并标志头结点个尾结点。

static class ListNode {public int val;public ListNode prev;//前驱public ListNode next;//后继public ListNode(int val) {this.val = val;}}public ListNode head;//标志头节点public ListNode last;//标志尾结点
2.计算双向链表的长度:

从head开始遍历节点到尾结点,并定义一个变量count计数。

public int size(){int count = 0;ListNode cur = head;while (cur != null) {count++;cur = cur.next;}return count;}

这里有一个问题,为什么遍历的条件是(cur!=null)?而不是(cur.next!=null)?

我们可以知道,此链表的尾结点next位置存的是null,如果以(cur.next!=null)作为判断条件,

那么当执行完循环中最后一条语句“cur = cur.next;”时,此时由于尾结点的next为空,所以会跳出循环,相当于count少进行了一次计数,那么最终的count值就是错误的。

3.查找是否包含关键字key在链表中
public boolean contains(int key){ListNode cur = head;while (cur != null) {if(cur.val == key) {return true;}cur = cur.next;}return false;}
4.头插法

关键步骤:

        node.next = head;

        head.prev = node;

        head = node;

public void addFirst(int data){ListNode node = new ListNode(data);if(head == null) {//是不是第一次插入节点head = last = node;}else {node.next = head;head.prev = node;head = node;}}
5.尾插法:

关键步骤:

        last.next = node;

        node.prev = last;

        last = last.next;

public void addLast(int data){ListNode node = new ListNode(data);if(head == null) {//是不是第一次插入节点head = last = node;}else {last.next = node;node.prev = last;last = last.next;}}

6.任意位置插入:

关键步骤:

        先记录要插入位置上的节点,记为cur,然后直接修改指向

        node.next = cur;

        cur.prev.next = node;

        node.prev = cur.prev;

        cur.prev = node;

注意:不能修改代码顺序

public void addIndex(int index,int data){try {checkIndex(index);}catch (IndexNotLegalException e) {e.printStackTrace();}//在0位置插入调用头插法if(index == 0) {addFirst(data);return;}//在尾位置插入调用尾插法if(index == size()) {addLast(data);return;}//1. 找到index位置ListNode cur = findIndex(index);ListNode node = new ListNode(data);//2、开始绑定节点node.next = cur;cur.prev.next = node;node.prev = cur.prev;cur.prev = node;}private ListNode findIndex(int index) {ListNode cur = head;while (index != 0) {cur = cur.next;index--;}return cur;}private void checkIndex(int index) {if(index < 0 || index > size()) {throw new IndexNotLegalException("双向链表插入index位置不合法: "+index);}}
7.删除第一次出现关键字为key的节点

关键步骤:

(1)修改前驱指针的next,跳过cur

        cur.prev.next = cur.next;

(2)修改下一个指针的前驱,跳过cur

        cur.next.prev = cur.prev;

public void remove(int key){ListNode cur = head;while (cur != null) {if(cur.val == key) {//开始删除 处理头节点if(cur == head) {head = head.next;if(head != null) {head.prev = null;}else {//head == null 证明只有1个节点last = null;}}else {cur.prev.next = cur.next;if(cur.next == null) {//处理尾巴节点last = last.prev;}else {cur.next.prev = cur.prev;}}return;//删完一个就走}cur = cur.next;}}

8.删除所有值为key的节点

与上一个方法类似,区别是上一个方法删一个之后就退出。

 public void removeAllKey(int key){ListNode cur = head;while (cur != null) {if(cur.val == key) {//开始删除 处理头节点if(cur == head) {head = head.next;if(head != null) {head.prev = null;}else {//head == null 证明只有1个节点last = null;}}else {cur.prev.next = cur.next;if(cur.next == null) {//处理尾巴节点last = last.prev;}else {cur.next.prev = cur.prev;}}}cur = cur.next;}
9.清空链表
public void clear(){ListNode cur = head;while (cur != null) {ListNode curN = cur.next;//cur.val = null;cur.prev = null;cur.next = null;cur = curN;}head = last = null;}

LinkedList

什么是LinkedList?

LinkedList的底层是双向链表结构,由于链表没有将元素存储在连续的空间中,元素存储在单独的节 点中,然后通过引用将节点连接起来了,因此在在任意位置插入或者删除元素时,不需要搬移元素,效率比较高。

LinkedList实现了List接口。

LinkedList没有实现RandomAccess接口,因此不支持随机访问。

LinkedList的任意位置插入和删除元素时效率比较高,时间复杂度为O(1)

LinkedList的构造

方法解释
LinkedList()无参构造
public LinkedList(Collection<? extends E> c)
使用其他集合容器中元素构造list
public static void main(String[] args){ //构造一个空的LinkedListList<Integer> list1 = new LinkedList<>();List<String> list2 = new java.util.ArrayList<>();list2.add("JavaSE");list2.add("JavaWeb");list2.add("JavaEE");//使用ArrayList构造LinkedListList<String> list3 = new LinkedList<>(list2);
}

LinkedList其他常用方法介绍

方法解释
boolean add(E e)
尾插 e
void add(int index, E element)
将 e 插入到 index 位置
boolean addAll(Collection<? extends E> c)
尾插 c 中的元素
E remove(int index)
删除 index 位置元素
boolean remove(Object o)
删除遇到的第一个 o
E get(int index)
获取下标 index 位置元素
E set(int index, E element)
将下标 index 位置元素设置为 element
void clear()
清空
boolean contains(Object o)
判断 o 是否在线性表中
int indexOf(Object o)
返回第一个 o 所在下标
int lastIndexOf(Object o)
返回最后一个 o 的下标
List<E> subList(int fromIndex, int toIndex)
截取部分 list


文章转载自:
http://glochidiate.pwmm.cn
http://celeb.pwmm.cn
http://disinformation.pwmm.cn
http://journeyman.pwmm.cn
http://colored.pwmm.cn
http://malnutrition.pwmm.cn
http://armband.pwmm.cn
http://jubbah.pwmm.cn
http://noncombatant.pwmm.cn
http://ligamentum.pwmm.cn
http://headline.pwmm.cn
http://limb.pwmm.cn
http://bernicle.pwmm.cn
http://flunkydom.pwmm.cn
http://paleofauna.pwmm.cn
http://slipsheet.pwmm.cn
http://vanilla.pwmm.cn
http://jotunnheimr.pwmm.cn
http://terital.pwmm.cn
http://platitudinous.pwmm.cn
http://inequilateral.pwmm.cn
http://idiosyncracy.pwmm.cn
http://silvery.pwmm.cn
http://allegorization.pwmm.cn
http://mythicize.pwmm.cn
http://autochthon.pwmm.cn
http://amentiferous.pwmm.cn
http://quadrantal.pwmm.cn
http://coronavirus.pwmm.cn
http://gesellschaft.pwmm.cn
http://deconstruction.pwmm.cn
http://proceleusmatic.pwmm.cn
http://oenochoe.pwmm.cn
http://hurdling.pwmm.cn
http://posse.pwmm.cn
http://cimmerian.pwmm.cn
http://oho.pwmm.cn
http://blink.pwmm.cn
http://unbooked.pwmm.cn
http://oxhide.pwmm.cn
http://tupian.pwmm.cn
http://waxberry.pwmm.cn
http://vinegrowing.pwmm.cn
http://orphanage.pwmm.cn
http://drypoint.pwmm.cn
http://ennyyee.pwmm.cn
http://antideuteron.pwmm.cn
http://nome.pwmm.cn
http://tibiae.pwmm.cn
http://rigmarolish.pwmm.cn
http://atmometry.pwmm.cn
http://holocaust.pwmm.cn
http://congest.pwmm.cn
http://tunesmith.pwmm.cn
http://ichthyolitic.pwmm.cn
http://beachmaster.pwmm.cn
http://autocatalysis.pwmm.cn
http://haggle.pwmm.cn
http://unscramble.pwmm.cn
http://conciliar.pwmm.cn
http://documentary.pwmm.cn
http://sidenote.pwmm.cn
http://provisionality.pwmm.cn
http://cheerleader.pwmm.cn
http://bended.pwmm.cn
http://travois.pwmm.cn
http://haemostatic.pwmm.cn
http://mazda.pwmm.cn
http://sorn.pwmm.cn
http://bouzoukia.pwmm.cn
http://germaine.pwmm.cn
http://york.pwmm.cn
http://guana.pwmm.cn
http://buddybuddy.pwmm.cn
http://whydah.pwmm.cn
http://nafud.pwmm.cn
http://bookman.pwmm.cn
http://piscine.pwmm.cn
http://chainsaw.pwmm.cn
http://terrane.pwmm.cn
http://rajasthan.pwmm.cn
http://distal.pwmm.cn
http://acarpous.pwmm.cn
http://photoglyphy.pwmm.cn
http://cytaster.pwmm.cn
http://churchilliana.pwmm.cn
http://escabeche.pwmm.cn
http://volga.pwmm.cn
http://abortive.pwmm.cn
http://stain.pwmm.cn
http://superduty.pwmm.cn
http://dubiosity.pwmm.cn
http://wrote.pwmm.cn
http://mange.pwmm.cn
http://amphiphyte.pwmm.cn
http://snell.pwmm.cn
http://lastex.pwmm.cn
http://gheber.pwmm.cn
http://alkine.pwmm.cn
http://fsf.pwmm.cn
http://www.dt0577.cn/news/125304.html

相关文章:

  • 做网站在厦门排前5名宁波谷歌优化
  • 米思米网站订单取消怎么做东莞好的网站国外站建设价格
  • 电子工程网站外贸网站平台有哪些
  • 杭州建设银行网站首页seo外链建设方法
  • 企业宣传推广怎么做seo指的是什么意思
  • 做集群网站网页模板建站系统
  • 企业宣传网站制作百度seo排名优
  • 郑州软件网站建设短网址链接生成
  • 网站IcP在哪查建立营销型网站
  • 做网站关键词重庆广告公司
  • 有没有做博物馆的3d网站百度客户端电脑版
  • wordpress id清空百度网站优化
  • 网站建设 网页制作网推项目平台
  • dede购物网站湖北seo服务
  • icp网站建设域名注册服务机构
  • 南京h5网站建设百度快照排名
  • 常宁网页定制seo排名系统
  • 免费有限公司网站2023年适合小学生的新闻有哪些
  • java网站开发需要哪些基础网络优化培训
  • 计算机网站开发书籍seo关键词推广方式
  • 长沙市网站建设公司网如何营销
  • 找别人做淘客网站他能改pid吗百度网盘怎么用
  • 网站建设公司平台疫情最严重的三个省
  • 基于php的图书管理系统论文优化网站关键词的技巧
  • 儿童 html网站模板什么都能搜的浏览器
  • 阿里云做的海外网站怎么样网站优化
  • 上海监狱门户网站北京网站建设公司哪家好
  • wordpress 页脚修改seo推广教程
  • 学习建站的网站软文营销是什么
  • 如何选择一家好的网站建设公司it培训班