LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 287|回复: 0

LinkedList实现 - Queue方法

[复制链接]
发表于 2023-12-20 15:14:30 | 显示全部楼层 |阅读模式

Queue 方法  

  1.     /**
  2.      * Retrieves, but does not remove, the head (first element) of this list.
  3.      *
  4.      * @return the head of this list, or {@code null} if this list is empty
  5.      * @since 1.5
  6.      */
  7.     public E peek() {
  8.         final Node<E> f = first;
  9.         return (f == null) ? null : f.item;
  10.     }

  11.     /**
  12.      * Retrieves, but does not remove, the head (first element) of this list.
  13.      *
  14.      * @return the head of this list
  15.      * @throws NoSuchElementException if this list is empty
  16.      * @since 1.5
  17.      */
  18.     public E element() {
  19.         return getFirst();
  20.     }

  21.     /**
  22.      * Retrieves and removes the head (first element) of this list.
  23.      *
  24.      * @return the head of this list, or {@code null} if this list is empty
  25.      * @since 1.5
  26.      */
  27.     public E poll() {
  28.         final Node<E> f = first;
  29.         return (f == null) ? null : unlinkFirst(f);
  30.     }

  31.     /**
  32.      * Retrieves and removes the head (first element) of this list.
  33.      *
  34.      * @return the head of this list
  35.      * @throws NoSuchElementException if this list is empty
  36.      * @since 1.5
  37.      */
  38.     public E remove() {
  39.         return removeFirst();
  40.     }

  41.     /**
  42.      * Adds the specified element as the tail (last element) of this list.
  43.      *
  44.      * @param e the element to add
  45.      * @return {@code true} (as specified by {@link Queue#offer})
  46.      * @since 1.5
  47.      */
  48.     public boolean offer(E e) {
  49.         return add(e);
  50.     }
复制代码


------
原文链接:https://pdai.tech/md/java/collection/java-collection-LinkedList.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表