不带头节点的单链表及其基本操作(Java实现)
来源:互联网 发布:nginx 查看模块 编辑:程序博客网 时间:2024/04/19 14:14
package lwh.linearlist.linklist;public class Node { protected int e; protected Node next; public Node(){}; public Node(int e){ this.e = e; } public Node(int e, Node next){ this.e = e; this.next = next; }}
package lwh.linearlist.linklist;import java.util.Scanner;//不带头节点的单链表public class LinkList { private Node head; public LinkList(){ head = null; } //头插法建立单链表 public void createListHead(){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int num = sc.nextInt(); if(num != 99){ Node node = new Node(num); node.next = head; head = node; }else{ break; } } } //递归删除不带头节点单链表中所有值为x的节点 public void delete(int x){ Node q = head; Node p = q; while(q != null && x != q.e){ p = q; q = q.next; } if(q == head){ head = q.next; q.next = null; q = null; delete(x); }else if(q != null){ p.next = q.next; q.next = null; q = null; delete(x); }else{ return; } } public void print() { if(head == null){ System.out.println("No num"); return; } System.out.print("["); for(Node node = head; node != null; node = node.next){ if(node.next != null) System.out.print(node.e + ","); else System.out.print(node.e + "]"); } System.out.println(); }}
阅读全文
0 0
- 不带头节点的单链表及其基本操作(Java实现)
- 带头节点的单链表及其基本操作(Java实现)
- 带头节点的双链表及其基本操作(Java实现)
- 数据结构(一)单链表的基本操作(不带头节点)
- 单链表的实现(不带头节点)
- 带头节点的单链表的基本操作
- 不带头节点的双向循环链表基本操作
- C语言实现单链表(不带头结点)的基本操作
- 链表操作(不带头节点的)
- 带头节点和不带头节点的单链表的区别
- C语言实现单链表(带头结点)的基本操作
- 数据结构双语课->不带头节点的单链表实现
- 不带头节点的链表尾插法C++实现
- 带头节点单链表的实现
- 不带头结点的单链表的基本操作
- 不带头结点的单链表的基本操作
- C语言实现双向非循环链表(不带头结点)的基本操作
- 不带头节点的双向循环链表的基本操作
- JVM调优总结(5):典型配置
- 关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
- PTA 7-6(队列) 银行排队问题之单队列多窗口加VIP服务(30 分) 30分代码
- JVM调优总结(6):新一代的垃圾回收算法
- 国庆清北刷题冲刺班 Day5 上午
- 不带头节点的单链表及其基本操作(Java实现)
- Gauge中文文档(10)—故障处理
- IIS与IIC
- imageLoader框架
- Java基础集合类(二):LinkedList详解
- 不爱说话?社交无能?或许你可以试试这种说话术
- 2017下半年ACM-ICPC网络赛签到题汇总
- 带头节点的双链表及其基本操作(Java实现)
- PTA 7-7(排序) Windows消息队列(25 分) 25分代码 优先队列