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

网站后端技术语言手工建站与模板网站的区别

网站后端技术语言,手工建站与模板网站的区别,住房城乡建设干部学院网站,站长工具排名查询🔥博客主页🔥:【 坊钰_CSDN博客 】 欢迎各位点赞👍评论✍收藏⭐ 目录 1. 什么是 LinkedList ? 2 LinkedList 的使用 2.1 LinkedList 的构造 2.2 LinkedList 的常用方法 2.3 LinkedList 的遍历 3. 单链表的模拟实现…

 🔥博客主页🔥:【 坊钰_CSDN博客 】

欢迎各位点赞👍评论✍收藏⭐

目录

1. 什么是 LinkedList ?

2 LinkedList 的使用

2.1 LinkedList 的构造

 2.2 LinkedList 的常用方法

2.3 LinkedList 的遍历

3. 单链表的模拟实现

3.1 基本框架

3.2 头插

3.3 尾插

3.4 在第 pos 位后面插入 val

3.5 打印

3.6 求大小

4. 全部源码

5. 小结


1. 什么是 LinkedList ?

对于存储数据来说,ArrayList 是有缺陷的,ArrayList 动态扩容时可能会有空间的损失,而 LinkedList 的元素存储在特定的节点中,通过引用来联系元素之间的关系,效率较高

LinkedList 也是实现了 List 接口

  •  LinkedList 的底层是使用了双链表
  • LinkedList 适合多次频繁插入和删除的场景

2 LinkedList 的使用

2.1 LinkedList 的构造

LinkedList 有两种构造方法

LinkedList()                            //空构造方法
LinkedList(Collection<? extends E>)     //以链表进行构造(必须为 E 的子类)
public class Test {public static void main(String[] args) {// 空构造LinkedList list1 = new LinkedList();// 以链表来构造LinkedList list2 = new LinkedList(list1);}}

 2.2 LinkedList 的常用方法

LinkedList 的常用方法 和 ArrayList的常用方法 基本一样,有兴趣可以看一下上一篇博客

【Java 数据结构】ArrayList 类 与 模拟实现顺序表-CSDN博客

2.3 LinkedList 的遍历

public class Test {public static void main(String[] args) {LinkedList<Integer> list = new LinkedList<>();list.add(1);list.add(2);list.add(3);list.add(4);list.add(5);// for-each 遍历for(Integer x : list)System.out.print(x);//使用迭代器遍历ListIterator<Integer> it = list.listIterator();while (it.hasNext()) {System.out.print(it.next() + " ");}}
}

3. 单链表的模拟实现

3.1 基本框架

public class MyLinkedList {public static class LinkedNode {int value;LinkedNode next;LinkedNode(int value) {this.value = value;}}
}

3.2 头插

/** 头插* */public void addInsert(int val) {LinkedNode node = new LinkedNode(val);if (head == null) {head = node;} else {node.next = head;head = node;}
}

3.3 尾插

/** 尾插* */public void fastInsert(int val) {LinkedNode node = new LinkedNode(val);if (head == null) {head = node;} else {LinkedNode ret = head;while (ret.next != null) {ret = ret.next;}ret.next = node;}
}

3.4 在第 pos 位后面插入 val

/** 在第 pos 位后面插入 val* */public void posInsert(int pos,int val) {LinkedNode node = new LinkedNode(val);if (pos <= 0 || pos > linkSize()) {System.out.println("Pos is No !");return;}if (pos == linkSize()) {fastInsert(val);return;}int count = pos - 1;LinkedNode ret = head;while (count != 0) {ret = ret.next;count--;}node.next = ret.next;ret.next = node;}

3.5 打印

/** 打印* */public void printList() {LinkedNode ret = head;while (ret != null) {System.out.print(ret.value+" ");ret = ret.next;}System.out.println();
}

3.6 求大小

/** 求大小* */public int linkSize() {int count = 0;LinkedNode ret = head;while (ret != null) {count++;ret = ret.next;}return count;
}

4. 全部源码

public class MyLinkedList {public static class LinkedNode {int value;LinkedNode next;LinkedNode(int value) {this.value = value;}}LinkedNode head;/** 打印* */public void printList() {LinkedNode ret = head;while (ret != null) {System.out.print(ret.value+" ");ret = ret.next;}System.out.println();}/** 求大小* */public int linkSize() {int count = 0;LinkedNode ret = head;while (ret != null) {count++;ret = ret.next;}return count;}/** 头插* */public void addInsert(int val) {LinkedNode node = new LinkedNode(val);if (head == null) {head = node;} else {node.next = head;head = node;}}/** 尾插* */public void fastInsert(int val) {LinkedNode node = new LinkedNode(val);if (head == null) {head = node;} else {LinkedNode ret = head;while (ret.next != null) {ret = ret.next;}ret.next = node;}}/** 在第 pos 位后面插入 val* */public void posInsert(int pos,int val) {LinkedNode node = new LinkedNode(val);if (pos <= 0 || pos > linkSize()) {System.out.println("Pos is No !");return;}if (pos == linkSize()) {fastInsert(val);return;}int count = pos - 1;LinkedNode ret = head;while (count != 0) {ret = ret.next;count--;}node.next = ret.next;ret.next = node;}
}

5. 小结

以上就是对 ArrayList 类 和 顺序表 的了解,具体还需宝子们去实践,如果觉得该博客对你有用的话,希望一键三连,点个关注不迷路,谢谢支持  

http://www.15wanjia.com/news/162732.html

相关文章:

  • 网站系统目前运行稳定那些网站是伪静态
  • 淘宝网站如何做虚拟高端手机网站设计
  • 如何将域名和网站绑定域名网站带做收录排名
  • 做婚恋网站怎么样监利网站
  • 做网站分析信息分类网站建设
  • 新闻cms静态网站模板下载中交路建子公司最新排名
  • 创建网站免费教做网站的学校
  • 杭州怎么做网站北京网站开开发公司电话
  • 微信网站建设企业网站推广营销效果
  • 高端网站设计百家号如何网站关键词优化
  • 手机网站建设做竞价推广的技巧东莞房价下跌最惨一览表
  • 大连建设网站制作淘宝上新推荐
  • 网站首页分辨率黄山高端网站建设
  • 网站描述修改手机上怎么做投票网站
  • 中国建设会计学会网站订制企业网站
  • 做电商的常去网站什么是网络营销渠道?网络营销渠道有何功能?
  • 个人网站做淘宝客犯法吗怎么建立一个博客网站吗
  • 重庆网络推广网站一流的高密做网站的
  • 国际学院网站建设的意义上海工商网查询
  • 新站网站收录减少seo岗位
  • 专业站移动端网站建设公司
  • 网站服务器异常是什么意思wordpress怎么换空间
  • asp业务网站seo相关岗位
  • 企业的门户网站一般用什么做中国新闻社是什么编制
  • 内蒙古网站制作公司成都装饰网站建设
  • 沭阳网站制作网站建设总体情况
  • 公司企业邮箱注册wix网站做seo如何
  • 网站营销推广计划网站开发公司会计处理
  • 设计logo素材工具seo
  • 做外贸网站违法吗学生静态网页模板