DESKTOP-S58I0I8_20200911-李春晓

问题 1 link

    public void add( int index , E e ) {
        if( index < 0 || index > count ) {
            throw new IllegalArgumentException( "索引超出范围" );
        }
        
        int x = 0 ; 
        Node<E> node = first ; 
        while( node != null ) {
            if( x == index ) {
                break ;
            }
            node = node.next ;
            x++ ;
        }
        
        System.out.println( node.item );
        Node<E> p = node.previous ;
        if( p == null ) { 
            Node<E> old = this.first ; 
            this.first = new Node<>( null , e , old );
            old.previous = this.first ; 
        } else {
            Node<E> n = new Node<>( p , e , node );
            p.next = n ;
            node.previous = n ;
        }
        
        count++ ;
        
    }

添加元素的时候面向的是一个对象,修改的是对象中的字段

已解决

吐槽

快乐学习