链表:

  • 一种常见的的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到是下一个节点的指针(Pointer)

  • 链表适合插入、删除、不宜过长、否则会导致遍历性能下降

功能实现:

  • 添加一个节点
  • 查询一个节点
  • 删除一个节点
  • 修改一个节点
  • 打印所有节点

代码实现:递归+内部类

public class Test1 {public static void main(String[] args) {NodeManager manager = new NodeManager();System.out.println("------add-------");manager.add("1");manager.add("2");manager.add("3");manager.add("4");manager.add("5");manager.print();System.out.println("----------del----------");manager.del("3");manager.print();System.out.println("----------update---------");manager.update("5", "6");manager.print();System.out.println("----------find------------");System.out.println(manager.find("2"));System.out.println("----------insert---------");System.out.println(manager.insert(2, "qijing"));manager.print();}
}class NodeManager {private Node node; // 根节点private int currentIndex = 0;// 节点的序号// 添加的方法public void add(String date) {if (node == null) {node = new Node(date);} else {node.add(date);}}// 删除的方法public void del(String date) {if (node != null) {if (node.getDate() == date) {node = node.next;} else {node.del(date);}}}// 打印所有节点public void print() {if (node != null) {System.out.print(node.getDate() + "->");node.print();System.out.println();}}//插入一个节点后面public boolean insert(int index, String date) {currentIndex = 0;if (node == null) {return false;}if (index == currentIndex) {Node node1 = new Node(date);node1.next = node.next;node.next = node1;return true;} else {return node.insert(index, date);}}// 查询是否存在节点public boolean find(String date) {if (node == null) {return false;}if (node.getDate() == date) {return true;} else {return node.find(date);}}//修改一个节点public void update(String oldNode, String newNode) {if (node != null) {if (node.getDate() == oldNode) {node.setDate(newNode);} else {node.update(oldNode, newNode);}}}private class Node {private String date;private Node next;public Node(String date) {this.date = date;}public void setDate(String date) {this.date = date;}public String getDate() {return this.date;}// 添加的方法public void add(String date) {if (this.next == null) {this.next = new Node(date);} else {this.next.add(date);}}// 查询是否存在节点public boolean find(String date) {if (this.next == null) {return false;}if (this.next.date == date) {return true;} else {return this.next.find(date);}}// 删除的方法public void del(String date) {if (this.next != null) {if (this.next.getDate() == date) {this.next = this.next.next;} else {this.next.del(date);}}}// 打印所有节点public void print() {if (this.next != null) {System.out.print(this.next.date + "->");this.next.print();}}//插入一个节点后面public boolean insert(int index, String date) {if (this.next == null) {return false;}currentIndex++;if (currentIndex == index) {Node node1 = new Node(date);node1.next = this.next.next;this.next.next = node1;return true;}return this.next.insert(index, date);}//修改一个节点public void update(String oldNode, String newNode) {if (this.next != null) {if (this.next.date == oldNode) {this.next.date = newNode;} else {this.next.update(oldNode, newNode);}}}}
}

简单链表实现增删改查(内部类+递归)相关推荐

  1. java file取不到linux文件_Java中高级核心知识全面解析——Linux基本命令(切换、增删改查、压缩文件、权限命令)...

    一.目录切换命令 cd usr: 切换到该目录下usr目录 cd ..(或cd../): 切换到上一层目录 cd /: 切换到系统根目录 cd ~: 切换到用户主目录 cd -: 切换到上一个操作所在 ...

  2. vue+element实现树状表格的增删改查;使用el-table树形数据与懒加载实现树状表格增删改查

    以下代码可以直接复制使用 一.情景: 列表是一个树状表格,可以无限添加下级,以及对列表的某一行进行增删改查(目前查没有写). 原博链接 二.本篇是在原博主的代码基础上添加了部分功能. 功能1: 给树状 ...

  3. abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与EasyUI结合增删改查之六(三十二)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...

  4. java定时任务增删改查_python实现crontab定时任务的增删改查

    python实现crontab定时任务的增删改查 python实现crontab定时任务的增删改查 本人主要业务方向是后台,在开发不同版本迭代或者项目的部署时,每次都手动去创建cron定时任务,很不符 ...

  5. 【Linux系统】第5节 Linux增删改查常用命令及查看命令字帮助手册

    目录 1 常用命令 1.1 查询 1.1.1 ls命令 1.1.2 cat命令 1.1.3 du命令 1.2 创建 1.2.1 touch命令 1.2.2 echo命令 1.2.3 mkdir命令 1 ...

  6. 用pymongo对mongoDB增删改查(CRUD)

    pymongo操作mongoDB的增删改查 | CRUD pymongo简介 连接本地mongoDB 连接远程MongoDB 数据库CRUD 使用现有数据库 增 删 改 查 集合CRUD 增 删 改 ...

  7. java File 读取本地文件 增删改查

    java 读取本地文件 增删改查 这里删除不做删除,只是对文件进行重命名,只是物理意义不可见,实际存在 用的jfinal框架 /*** 列出指定路径的文件* @param path 路径* @retu ...

  8. Zookeeper后端开发工具Curator的使用 | Curator对节点的增删改查 | ACL权限控制 | 分布式锁 | 分布式计数器 | 附带最新版本下载

    前言 Curator是Apache开源的一个Java工具类,通过它操作Zookeeper会变得极度舒适! 前置条件:已掌握的基本操作,比如在后台可以增减节点.ACL权限设置等. 1.Zookeeper ...

  9. 单链表LinkedList的增删改查

    数组作为数据存储结构有一定的缺陷.在无序数组中,搜索性能差,在有序数组中,插入效率又很低(插入位置后面的元素需要集体后移),而且这两种数组的删除效率(集体前移)都很低,并且数组在创建后,其大小是固定了 ...

  10. Android本地文件管理器思路解析一一增删改查具体实现

    花了一天的时间撸完了Android本地文件管理器~!!GitHub下载地址为:PumpkinFileManager 南瓜文件管理器1.0. 功能列表: 1: 实现了在ListView中浏览本地所有文件 ...

最新文章

  1. linux 中~$和/$的区别?
  2. Docker Centos 7.X部署Tomcat 并且修改Server.xml配置文件方案 并设置时区 只要十一步
  3. 编程开发之--java多线程学习总结(3)类锁
  4. 最详细MySQL的安装与介绍Windows
  5. laravel php7.2报错,laravel,php_运行php artisan serve时报错,laravel,php - phpStudy
  6. 钉钉下载与安装过程 适用于windows系统 20200718
  7. mysql 查询数据库名是否存在_SQL查询数据库是否存在
  8. 【ES】ES检索的时候特殊字符该怎么处理
  9. 斯坦福吴恩达团队公布最大医学影像数据集
  10. mongotemplate.insert 是否成功判断_河北外观专利申请成功的必要条件
  11. 用循环队列模拟滑动窗口动态求最值及峰峰值
  12. win10打开计算机出现马赛克,主编处理win10系统播放视频影片出现锯齿、马赛克、模糊的办法?...
  13. python语法错误怎么办_Python中出现语法错误时解决方法
  14. 教你用illustrator画十二色环
  15. BC26低功耗的OPENCPU代码注意事项
  16. 4k纸是几厘米乘几厘米_几厘米?4k的纸多大?
  17. 2020国庆节法定假日是几天呢?
  18. 可长时间佩戴的耳机真的存在吗?骨传导耳机是否对耳朵伤害更小?
  19. Flight_Simulator(DHC-2‘Beaver’aircraft )
  20. 汇编语言程序设计实验——字符统计

热门文章

  1. 架构师:成为架构师可能会面临的问题
  2. SWUST OJ Coin Changing
  3. ValidationKey
  4. MPI集群安装、MPI安装
  5. php替换字符串字符,php替换字符串中间字符为省略号的方法
  6. 学习Scala:孤立对象的实现原理
  7. 如何用vs2013开发人员命令提示工具执行一个方法(一个简单的demo)
  8. 阿里云HPC--人工智能加速利器
  9. [android] fragment的动态创建
  10. 共享内存shared pool (3):Library cache