模拟集合链表

模拟集合链表,第1张

 

  public static void main(String[] args) {
        //创建node数组
        Node s[] =new Node[16];
        //创建node对象
        Node tom = new Node("tom", null);
        //下标为2赋值为tom
        s[2]=tom;
        //创建第二个node对象
        Node jack = new Node("jack", null);
        //把jack挂载到tom的后面
         tom.next=jack;
        //创建第三个node对象
        Node rose = new Node("rose", null);
        //把rose挂载到jack的后面
        jack.next=rose;
    }
}class Node{//结点 存储数据  可以指向下一个结点  形成链表
    Object item;//存放数据
    Node next;//指向下一个结点
    Node port;//指向前一个结点

    public Node(Object item, Node next) {
        this.item = item;
        this.next = next;
    }

    @Override
    public String toString() {
        return "Node{" +
                "item=" + item +
                ", next=" + next +
                ", port=" + port +
                '}';
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/923396.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存