zoukankan      html  css  js  c++  java
  • 数据结构____单链表

    public class WordLinkedList {
        
        private static class Node{
            private char element;
            private Node next;
            private Node(char element){
                this.element=element;
            }
        }
        
        private Node root;
        
        private Node tail;
        
        public void add(char item){        
             //方法一 性能高
            Node nodeNew=new Node(item);
            if(root==null){
                root=tail=nodeNew;
                return;
            }
            
            tail.next=nodeNew;
            tail=tail.next;
            
            /*
             * 方法二
             * Node nodeNew=new Node(item);        
            Node current=root;
            Node pre=null;
            while(current!=null){
                pre=current;
                current=current.next;
            }        
            if(pre==null){
                root=nodeNew;
            }
            else{
                pre.next=nodeNew;
            }*/
        }
        
        public void add(String word){
            for (int i = 0; i < word.length(); i++) {
                add(word.charAt(i));
            }
        }
        
        public String toString(){
            StringBuilder buff=new StringBuilder();
            Node current=root;
            while(current!=null){
                buff.append(current.element);
                current=current.next;
            }
            return buff.toString();
        }    
    }

  • 相关阅读:
    卤菜技巧
    JS实现延迟
    软件项目版本号的命名规则及格式
    EF复合主键
    验证码和验证控件
    还原数据库,数据库提示正在还原中的处理办法
    更新汇总行
    centOS7挂在windows移动硬盘方法
    关于this、Echarts中的data
    SQLServer 查看SQL语句的执行时间
  • 原文地址:https://www.cnblogs.com/i80386/p/2484478.html
Copyright © 2011-2022 走看看