zoukankan      html  css  js  c++  java
  • Java代码模拟链表

    package other;
    
    class Link{
        private Node root;
        
        class Node{
           private String name;
           private Node Next;
           public Node(String name){
               this.name = name;
           }
           public String getName(){
               return this.name;
           }
           public void addNode(Node newNode){
               if(this.Next==null){
                   this.Next = newNode;
               }else{
                   this.Next.addNode(newNode);
               }
           }
           public void printNode(){
               System.out.print(this.name + "-->");
               if(this.Next!=null){
                   this.Next.printNode();
               }
           }
        };
        public void add(String name){
            Node newNode = new Node(name);
            if(this.root==null){
                this.root = newNode;
            }else{
                this.root.addNode(newNode);
            }
        }
        public void print(){
            if(this.root!=null){
                this.root.printNode();
            }
        }
    };
    
    public class LinkDemo {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
              Link link = new Link();
              link.add("根节点");
              link.add("第一节点");
              link.add("第二节点");
              link.add("第三节点");
              link.add("第四节点");
              link.print();
              System.out.println("null");
              
        }
    
    }
  • 相关阅读:
    hrbust1841再就业(状态压缩dp)
    并查集 poj2236
    JavaScript 常用单词整理
    HTML/CSS 常用单词整理
    HTML/CSS 知识点
    JavaScript 知识点
    ArcGIS裁剪影像数据
    小小程序员
    ArcGIS平面阴影制作
    前端相关的seo技术
  • 原文地址:https://www.cnblogs.com/lxh520/p/8358338.html
Copyright © 2011-2022 走看看