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

  • 相关阅读:
    A journey on the Android Main Thread
    android的消息处理机制(图+源码分析)——Looper,Handler,Message
    用fragment创建一个选项卡
    fragment的生命周期
    动态创建fragment
    自定义自动换行布局
    Android开源框架Universal-Image-Loader完全解析(三)
    第七章 摄影技术
    第六章 镜头的成像像质评价
    第五章 镜头像差的成因,校正及规避方法
  • 原文地址:https://www.cnblogs.com/i80386/p/2484478.html
Copyright © 2011-2022 走看看