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);
        }
    
  • 相关阅读:
    平均要取多少个(0,1)中的随机数才能让和超过1
    perl学习笔记
    K-means
    Mysql数据库常用操作整理
    ETL模型设计
    c++ 面试整理
    vim display line number
    inux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用
    Linux命令大总结
    perl learning
  • 原文地址:https://www.cnblogs.com/mxjhaima/p/13942839.html
Copyright © 2011-2022 走看看