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

伍佰亿网站怎样电商网络推广

伍佰亿网站怎样,电商网络推广,通化市城乡建设局网站,出行南宁app软件下载目录 一、链表 1.1链表的概念及结构 1.2 无头双向循环链表的实现 二、LinkedList的使用 2.1 LinkedList的构造方法 2.2 LInkedList的遍历 我们之前已经了解了ArrayList的使用,也已知它的底层是使用数组来储存元素。那么当我们使用ArrayList并且插入元素或者删…

目录

一、链表

1.1链表的概念及结构

1.2 无头双向循环链表的实现

二、LinkedList的使用

2.1 LinkedList的构造方法

2.2 LInkedList的遍历


        我们之前已经了解了ArrayList的使用,也已知它的底层是使用数组来储存元素。那么当我们使用ArrayList并且插入元素或者删除元素时,我们都需要移动插入或删除位置的后续元素,时间复杂度为O(n),将耗费大量时间。由此我们得知,如果我们需要对数据频繁插入删除,ArrayList则不适用这种场景。所以我们今天来学习LinkedList,链表结构。

一、链表

1.1链表的概念及结构

LinkedList在物理存储结构上是非连续的存储结构,我们使用引用链接次序实现连续的逻辑顺序。

从上图可以看出,链表结构在逻辑上是连续的,但是在物理上不一定连续

根据链表的不同特质,可以分成8种不同的链表结构

1.单向或者双向

2.带头或者不带头

3.循环或者不循环

8种链表结构,我们重点掌握两种:

无头单向非循环链表:结构简单,更多作为其他数据结构的子结构,在笔试面试中出现很多

无头双向循环链表:在Java中LinkedList底层实现的就是无头双向循环链表

1.2 无头双向循环链表的实现

public class LinkedList {static class ListNode{int val;ListNode next;ListNode prev;public ListNode(int val){this.val=val;}}ListNode head;ListNode last;//头插法public void addFirst(int data){ListNode node=new ListNode(data);if(head==null){head=last=node;return;}node.next=head;head=node;}//尾插法public void addLast(int data){ListNode node=new ListNode(data);if(head==null){head=last=node;return;}node.prev=last;last.next=node;last=node;}//任意位置插入,第一个数据节点为0号下标public void addIndex(int index,int data){if(index<0||index>size()){return;}if(index==0){addFirst(data);}else if(index==size()-1){addLast(data);}else{ListNode node=new ListNode(data);ListNode cur=head;int count=0;while(count!=index){count++;cur=cur.next;}node.next=cur;node.prev=cur.prev;node.prev.next=node;cur.prev=node;}}//查找是否包含关键字key是否在单链表当中public boolean contains(int key){ListNode cur=head;while(cur!=null){if(cur.val==key){return true;}}return false;}//删除第一次出现关键字为key的节点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{last=null;}}else{if(cur==last){last=cur.prev;cur.prev.next=cur.next;}else{cur.next.prev=cur.prev;cur.prev.next=cur.next;}}return;}else{cur=cur.next;}}}//删除所有值为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{last=null;}}else{if(cur==last){last=cur.prev;cur.prev.next=cur.next;}else{cur.next.prev=cur.prev;cur.prev.next=cur.next;}}}else{cur=cur.next;}}}//得到单链表的长度public int size(){int count=0;ListNode cur=head;while(cur!=null){count++;cur=cur.next;}return count;}//打印链表public void display(){ListNode cur=head;while(cur!=null) {System.out.println(cur.val + " ");cur = cur.next;}}//清除链表public void clear(){ListNode cur=head;ListNode curN=head.next;while(cur!=null){cur.next=cur.prev=null;cur=curN;curN=curN.next;}head=last=null;}
}

二、LinkedList的使用

2.1 LinkedList的构造方法

方法解释
LinkedList( )无参构造
public LinkedList(Collection<? extends E> c)使用其他集合容器中元素构造List
public class Test {public static void main(String[] args) {//无参构造LinkedList<Integer> List1=new LinkedList<>();List1.addFirst(1);List1.addFirst(2);List1.addFirst(3);System.out.println(List1);        //[3, 2, 1]//带参数构造LinkedList<Integer> List2=new LinkedList<>(List1);List2.addFirst(99);System.out.println(List2);        //[99, 3, 2, 1]}
}
方法

解释

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

2.2 LInkedList的遍历

    public static void main(String[] args) {LinkedList<Integer> list = new LinkedList<>();list.add(1); // add(elem): 表示尾插list.add(2);list.add(3);list.add(4);list.add(5);list.add(6);list.add(7);System.out.println(list.size());// foreach遍历for (int e:list) {System.out.print(e + " ");            // 1 2 3 4 5 6 7 }System.out.println();// 使用迭代器遍历---正向遍历ListIterator<Integer> it = list.listIterator();while(it.hasNext()){System.out.print(it.next()+ " ");    // 1 2 3 4 5 6 7 }System.out.println();// 使用反向迭代器---反向遍历ListIterator<Integer> rit = list.listIterator(list.size());while (rit.hasPrevious()){System.out.print(rit.previous() +" ");    // 7 6 5 4 3 2 1 }System.out.println();}

http://www.dtddedu.com/news/440.html

相关文章:

  • 技术专业网站建设互联网广告营销方案
  • 网站招代理线上卖护肤品营销方法
  • 新手学做网站 cs5 pdf哈尔滨网站制作软件
  • 淘宝客的网站是自己做的吗优化营商环境工作总结
  • 购物网站建设项目策划书泉州百度首页优化
  • 商梦建站app开发成本预算表
  • 长春阿凡达网站建设深圳网络推广最新招聘
  • 微商城手机网站制作公司上海最新发布最新
  • 深圳画册设计品牌aso优化吧
  • 阿里巴巴网站怎么做seo搜索是什么
  • 装潢设计工作室排名优化课程
  • 网站备案人授权日本今日新闻头条
  • 杭州下沙网站建设时事热点新闻
  • 嘉兴企业网站制作广告设计公司
  • h5制作官网登录淘宝seo什么意思
  • 微网站建设难不难郑州网络推广公司
  • 个人可以做公益网站吗软文营销文章案例
  • 网站建设特效素材网站推广优化是什么意思
  • 网站背景尺寸大数据培训
  • 企业怎么做网站做网站的公司搜索引擎优化排名案例
  • 有哪些可以做策划方案的网站北京seo公司
  • 网站加入联盟如何做好seo优化
  • 建网站哪个公司好青岛seo网络推广
  • 阿里云做网站多少钱樱花bt引擎
  • 做网推的网站苏州百度推广开户
  • 关于绿色环保网站的建设历程久久seo综合查询
  • 五金配件东莞网站建设技术支持促销策略
  • 网站结构分析怎么做seo1搬到哪里去了
  • 大型网站稳定性建设视频课程推广seo优化公司
  • 机械做网站好处如何搭建公司网站