java 数据结构之 链式线性表
来源:互联网 发布:c语言转换汇编语言 编辑:程序博客网 时间:2024/05/24 11:13
package com.xdl.data_stru;public class Day_Two_LinkNode extends Day_Two_Node{ /*双向链表的node * public Day_Two_LinkNode prior;*/ public Day_Two_LinkNode next; public Day_Two_LinkNode getNext() { return next; } public void setNext(Day_Two_LinkNode next) { this.next = next; } /** * 初始化头部 */ public Day_Two_LinkNode() {super.nKey =' ';super.nNum = 0 ; } public Day_Two_LinkNode(int nKey, int nNum) {super(nKey, nNum); }}package com.xdl.data_stru;/** * @author xudaolong * 单链表:引入头结点,可存储线性表长度的信息,且末结点的指针域为null(以^表示,若头结点的指针域为null,则该表为空表) * 特点:物理逻辑顺序不一致;顺序存取方式 * 关键弄明白: p 与 p.next 关系 * 双向链接的:主要处理p.next 和 p.prior 以及 p.next.prior /p.prior.next 关系就ok叻 */@SuppressWarnings("unused")public class Day_Two_LinkTable { /** * head:头部,len已存在的元素个数 */ public Day_Two_LinkNode head; private int len; /** * @return 核心:对头部的初始,跟seqTable相似也要分配好data的大小 */ private boolean init() {this.head = new Day_Two_LinkNode();if (this.head == null) { return false;}/*循环单链表的初始化 * this.head.next= this.head; * this.len = 0; * */return true; } /** * 借刀杀人,目的将p.next为空 */ private void clear_node() {Day_Two_LinkNode p = this.head, q;/*循环单链表的判定 * p != null改为 p!= this.head*/while (p != null) { q = p; p = p.next; q.next = null;// q.next 就是 p 的后一个对象 q = null;} } /** * 销毁 */ private void ruin() {clear_node();this.len = 0;this.head = null; } /** * 清空 */ private void clear() {clear_node();this.len = 0; } private int get_length() {return this.len; } private boolean isEmpty() {if (this.len == 0) { return true;} else { return false;} } /** * @param i * @return 核心:判断i的范围,然后由p遍历i次; */ private Day_Two_LinkNode get_i_elem(int i) {if (i < 1 || i > this.len + 1) { return null;}Day_Two_LinkNode p = this.head.next; // 从第一个开始int j = 1;while (j != i) { p = p.next; j++;}return p; } /** * @param e * @return 核心:当e.equals(p)为真的时候,则返回当前的i值,再判断i的范围 */ private int get_e_elem(Day_Two_LinkNode e) {Day_Two_LinkNode p = this.head.next; // 从第一个开始int i = 1;// 作用只是能得到第几个值而已/*循环单链表的判定 * p != null改为 p!= this.head*/while (p != null && !e.equals(p) && this.isEmpty()) { p = p.next; i++;}if (i > this.len) { return 0;}return i; } /** * @param e * @return 核心:跟游戏中换装备一样,先把身上(this.head.nex)放到包裹中(q),然后换上,如此循环 */ private Day_Two_LinkNode get_prior_elem(Day_Two_LinkNode e) {Day_Two_LinkNode p = this.head.next;Day_Two_LinkNode q = this.head;/*循环单链表的判定 * p != null改为 p!= this.head*/while (p != null && !e.equals(p) && this.isEmpty()) { q = p;// 这个就是我们想要的值,返回前驱 p = p.next;}if (p == null) { return null;}return q; } /** * @param e * @return 核心:不用管丢失前驱 */ private Day_Two_LinkNode get_next_elem(Day_Two_LinkNode e) {Day_Two_LinkNode p = this.head.next;/*循环单链表的判定 * p != null改为 p!= this.head*/while (p != null && !e.equals(p) && this.isEmpty()) { p = p.next;}if (p != null) { p = p.next;}return p; } /** * @param i * @param e * @return 思考,对值的判断,找到第i-1的元素 表达关系是 0 --> <i-1 */ private int inser_i_elem(int i, Day_Two_LinkNode e) {if (i < 1 || i > this.len + 1) { return 0;}Day_Two_LinkNode p = this.head;int j = 0;while (j < i - 1) { p = p.next; j++;}e.next = p.next;p.next = e;this.len++;return 1; } private int insert_e_elem(Day_Two_LinkNode a, Day_Two_LinkNode b) {Day_Two_LinkNode p = this.head;while (p != null && !a.equals(p) && this.isEmpty()) { p = p.next;}if (p.next == null) { return 0;}b.next = p.next;p.next = b;this.len++;return 1; } private int insert_head_elem(Day_Two_LinkNode e) {Day_Two_LinkNode p =this. head;e.next = p.next;p.next = e;this.len++;return 1; }}
0 0
- java 数据结构之 链式线性表
- 数据结构之链式线性表
- 常用数据结构之linklist链式线性表
- 数据结构之线性表的链式存储
- 数据结构:线性表之链式存储结构
- 【数据结构】线性表之链式存储结构
- 数据结构:线性表之链式存储结构
- java常用数据结构---线性表---链式存储
- 数据结构(4)之线性表之单链式存储
- JAVA数据结构之线性表的链式存储结构——循环链表
- JAVA数据结构之线性表的链式存储结构——双向链表
- 数据结构学习----线性表的链式表示之升序排序的单链表(Java实现)
- 数据结构学习----线性表的链式表示之循环单链表(Java实现)
- 数据结构学习----线性表的链式表示之循环双链表(Java实现)
- JAVA数据结构之线性表的链式存储结构——单链表
- 数据结构:线性表之链式表实战演练
- 进击的数据结构二之线性表的链式结构
- 数据结构笔记之线性表的链式存储结构
- 程序设计方法学基本概念汇总
- MYSQL启动后报:ERROR! The server quit without updating PID file错误的问题解决
- 组件的使用(一)Spinner的使用
- HDU 4283 You Are the One(区间dp)
- 二叉树的遍历
- java 数据结构之 链式线性表
- ios 随机数 int x = arc4random() % 100;
- 贴个模板,POJ 1511
- bind搭建dns,ping域名需要几秒才能通
- 关于文件和文件夹在复制后属性时间变化的细节问题
- 03_TortoiseGit冲突和补丁演示,补丁冲突
- 《开源公开课1》:开源框架构建与实践
- java 数据结构之 顺序存储结构 栈
- HDU 1686 Oulipo