zoukankan      html  css  js  c++  java
  • LinkedList的几个元素操作方法

    看完这几个方法的源码,大概我们知道了,LinkedList不仅实现了队列先进先出 (使用 addremove )也实现了栈的 先进后出 (使用poppush)

    • remove 移除头部元素 Retrieves and removes the head (first element) of this list. @throws NoSuchElementException if this list is empty
    public E remove() {
            return removeFirst();
        }
    
    • poll 移除头部元素 空队列返回null Retrieves and removes the head (first element) of this list.
    public E poll() {
            final Node<E> f = first;
            return (f == null) ? null : unlinkFirst(f);
        }
    
    • pop 栈顶取出 也就是从队列最前面取出 Pops an element from the stack represented by this list. In other words, removes and returns the first element of this list.@throws NoSuchElementException if this list is empty
    public E pop() {
            return removeFirst();
        }
    
     public E removeFirst() {
            final Node<E> f = first;
            if (f == null)
                throw new NoSuchElementException();
            return unlinkFirst(f);
        }
    
    • add 在队列最末尾添加Inserts the specified element at the specified position in this list.
    public boolean add(E e) {
            linkLast(e);
            return true;
        }
    
    • push 压如栈顶。也就是队列最前面插入 Pushes an element onto the stack represented by this list. In other words, inserts the element at the front of this list.
    public void push(E e) {
            addFirst(e);
        }
    
  • 相关阅读:
    2020杭电多校第二场 1006.The Oculus
    2020杭电多校第一场 1005.Fibonacci Sum
    数论——中国剩余定理
    数论——线性同余方程
    数论——乘法逆元
    数论——裴蜀定理
    javascript预解析和作用域
    数组的排序..........加深难度
    值类型和引用类型
    js中的==和===
  • 原文地址:https://www.cnblogs.com/mxjhaima/p/13942839.html
Copyright © 2011-2022 走看看