zoukankan      html  css  js  c++  java
  • Java数据结构

    class DoubleLoopNode {
        // 上一个节点
        DoubleLoopNode pre;
        // 下一个节点
        DoubleLoopNode next;
        // 节点的内容
        int data;
    
        public DoubleLoopNode(int value) {
            this.pre = this;
            this.next = this;
            this.data = value;
        }
    
        // 插入节点
        public void append(DoubleLoopNode node) {
            // 原来的下一个节点
            DoubleLoopNode nextNode = this.next;
            // 把新节点作为当前节点的下一个节点
            this.next = node;
            // 把当前节点作为新节点的前一个节点
            node.pre = this;
            // 让原来的下一个节点作为新节点的下一个节点
            node.next = nextNode;
            // 让原来的下一个节点的上一个节点为新节点
            nextNode.pre = node;
        }
    
        // 获取下一个节点
        public DoubleLoopNode next() {
            return this.next;
        }
    
        // 获取上一个节点
        public DoubleLoopNode pre() {
            return this.pre;
        }
    
        // 获取数据
        public int getData() {
            return this.data;
        }
    }
    
    public class Main {
        public static void main(String[] args) {
            // 创建节点
            DoubleLoopNode dln1 = new DoubleLoopNode(1);
            DoubleLoopNode dln2 = new DoubleLoopNode(2);
            DoubleLoopNode dln3 = new DoubleLoopNode(3);
    
            // 追加节点
            dln1.append(dln2);
            dln2.append(dln3);
    
            // 查看所有节点
            System.out.println(dln2.pre().getData());
            System.out.println(dln2.getData());
            System.out.println(dln2.next().getData());
        }
    }
  • 相关阅读:
    「学习记录」《数值分析》第三章计算实习题(Python语言)
    Set原理
    字符串流stringReader
    Collection List接口
    io
    Dubbo 服务容错Hystrix
    Duboo 与springboot整合
    读取配置文件
    springboot 端口号
    springboot 多环境选择
  • 原文地址:https://www.cnblogs.com/GjqDream/p/11596027.html
Copyright © 2011-2022 走看看