zoukankan      html  css  js  c++  java
  • JAVA8 LinkedList

    package link_list.src;
    
    public class TestOne {
    
        /**
         * 
         * 1.无参构造方法和有参构造方法
         * 
         * 2. public boolean add(E e) {} 方法
         * 
         * 3.public E remove(int index) {}  删除指定位置的节点元素
         * 
         * 
         */
    
        
        
        /*
         * 2.
         * 对last操作,添加新节点的时候,把last作为pre,并对last重新复制,这样就形成了双向链表
         * 
         * 
        void linkLast(E e) {
            final Node<E> l = last;
            final Node<E> newNode = new Node<>(l, e, null);
            last = newNode;
            if (l == null)
                first = newNode;
            else
                l.next = newNode;
            size++;
            modCount++;
        }
        */
        
    /*    
     * 根据索引获取节点的值
     * 
        Node<E> node(int index) {
            // assert isElementIndex(index);
    
            if (index < (size >> 1)) {
                Node<E> x = first;
                for (int i = 0; i < index; i++)
                    x = x.next;
                return x;
            } else {
                Node<E> x = last;
                for (int i = size - 1; i > index; i--)
                    x = x.prev;
                return x;
            }
        }
        
            E unlink(Node<E> x) {
            // assert x != null;
            final E element = x.item;
            final Node<E> next = x.next;
            final Node<E> prev = x.prev;
    
            if (prev == null) {
                first = next;
            } else {
                prev.next = next;
                x.prev = null;
            }
    
            if (next == null) {
                last = prev;
            } else {
                next.prev = prev;
                x.next = null;
            }
    
            x.item = null;
            size--;
            modCount++;
            return element;
        }
        
        *
        *把前一个节点的next指向当前节点的next
        *把当前节点的next的prev指向当前节点的prev
        *
        *把当前节点的prev,next,item置空
        *
        E unlink(Node<E> x) {
            // assert x != null;
            final E element = x.item;
            final Node<E> next = x.next;
            final Node<E> prev = x.prev;
    
            if (prev == null) {
                first = next;
            } else {
                prev.next = next;
                x.prev = null;
            }
    
            if (next == null) {
                last = prev;
            } else {
                next.prev = prev;
                x.next = null;
            }
    
            x.item = null;
            size--;
            modCount++;
            return element;
        }
        
        
        */
    }
  • 相关阅读:
    希腊字母写法
    The ASP.NET MVC request processing line
    lambda aggregation
    UVA 10763 Foreign Exchange
    UVA 10624 Super Number
    UVA 10041 Vito's Family
    UVA 10340 All in All
    UVA 10026 Shoemaker's Problem
    HDU 3683 Gomoku
    UVA 11210 Chinese Mahjong
  • 原文地址:https://www.cnblogs.com/lxh520/p/9241656.html
Copyright © 2011-2022 走看看