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();
        }    
    }

  • 相关阅读:
    Docker简单的使用命令
    iPad 3g版完美实现打电话功能(phoneitipad破解)
    提供一个免费的CSDN下载账号
    2011年一次面试的实际记录
    VC皮肤库SkinSharp 1.0.6.6的使用
    oracle 数组
    从网页抓取数据的一般方法
    IJ:Idea 常用代码
    un-公司-Continental AG(大陆集团):百科
    un-公司-维珍集团:百科
  • 原文地址:https://www.cnblogs.com/i80386/p/2484478.html
Copyright © 2011-2022 走看看