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);
        }
    
  • 相关阅读:
    AngularJS方法 —— angular.bind
    rails 部署 nginx + passenger
    查找并删除
    rails 网站跨域
    From Ruby array to JS array in Rails- 'quote'?
    rails 网站字体
    form_tag
    bundle install 老是中断,可以在gemfile里面把source换成taobao源,可以自动安装
    ruby 功力修炼
    bootstrap 移动自适应界面
  • 原文地址:https://www.cnblogs.com/mxjhaima/p/13942839.html
Copyright © 2011-2022 走看看