链表功能的增加
来源:互联网 发布:php sql注入漏洞 编辑:程序博客网 时间:2024/05/17 03:50
今天晚上我完善了一下链表的功能,添加了两个删除功能:一个是输入字符串删除,而另一个是输入数字下标删除。
代码如下:
//删除一个节点public boolean delete(String value){if(head.getValue() == value){head = head.getNext();return true;}Node node = head.getNext();Node fistnode = head;while(node.getNext()!=null){if(node.getValue() == value){fistnode.setNext(fistnode.getNext().getNext());}fistnode = fistnode.getNext();node = node.getNext();}return false;}public boolean delete(int index){if(head == null||index>size()){try {throw new Exception("下标越界或者头结点为空,无法删除");} catch (Exception e) {e.printStackTrace();}return false;}if(index == 0){Node node = head;head = head.getNext();node.setNext(null);return true;}int count = 0;Node node = head;while(count != index-1){node = node.getNext();count++;}node.setNext(node.getNext().getNext());return true;}
下面是测试结果:
添加了删除功能后的链表功能更加的完善了。
2 0
- 链表功能的增加
- java中链表功能的实现
- 数据结构链表功能的实现
- 单链表功能大全
- 单链表功能大全
- Python中实现map+链表功能的方法
- C语言-----循环双向链表(增加文件读写链表功能)
- Ajax 与交叉表功能的项目
- Oracle的在线重定义表功能
- Oracle的在线重定义表功能
- Oracle的在线重定义表功能
- Mondrian打开聚合表功能的配置
- 测试Atlas的分表功能
- 用C实现基本链表功能
- 【1】C++实现内核链表功能
- Oracle的在线重定义表功能 (一)
- 【转】 Oracle的在线重定义表功能
- 自己写了一个链表功能还不完善但是简单的增删改查功能都已经实现了
- hiho一下 第八十八周
- ubuntu下利用gcc编译C语言程序
- 1008. Elevator (20)
- CGRect转为string
- 4. PathVariable、RequestParam、 CookieValue、SessionAttributes、ResponseBody、RequestHeader注解类
- 链表功能的增加
- 这两天做leetcode的心得
- LeetCode 2016 282,241
- Leetcode:26. Remove Duplicates from Sorted Array(JAVA)
- 在Android开发中遇到java.lang.NoClassDefFoundError的一般解决办法
- UDP是什么、及UDP和TCP的区别?
- 毕业设计第二十天
- Servlet 工作原理解析
- 最小生成树 Prim