14 |
|
* the <tt>LinkedList</tt> class provides uniformly named methods to |
15 |
|
* <tt>get</tt>, <tt>remove</tt> and <tt>insert</tt> an element at the |
16 |
|
* beginning and end of the list. These operations allow linked lists to be |
17 |
< |
* used as a stack, queue, or double-ended queue ({@link Deque}).<p> |
17 |
> |
* used as a stack, {@linkplain Queue queue}, or {@linkplain Deque |
18 |
> |
* double-ended queue}. <p> |
19 |
|
* |
20 |
|
* The class implements the <tt>Deque</tt> interface, providing |
21 |
|
* first-in-first-out queue operations for <tt>add</tt>, |
443 |
|
|
444 |
|
/** |
445 |
|
* Retrieves, but does not remove, the head (first element) of this list. |
446 |
< |
* @return the head of this queue, or <tt>null</tt> if this queue is empty. |
446 |
> |
* @return the head of this list, or <tt>null</tt> if this list is empty. |
447 |
|
* @since 1.5 |
448 |
|
*/ |
449 |
|
public E peek() { |
454 |
|
|
455 |
|
/** |
456 |
|
* Retrieves, but does not remove, the head (first element) of this list. |
457 |
< |
* @return the head of this queue. |
458 |
< |
* @throws NoSuchElementException if this queue is empty. |
457 |
> |
* @return the head of this list. |
458 |
> |
* @throws NoSuchElementException if this list is empty. |
459 |
|
* @since 1.5 |
460 |
|
*/ |
461 |
|
public E element() { |
464 |
|
|
465 |
|
/** |
466 |
|
* Retrieves and removes the head (first element) of this list. |
467 |
< |
* @return the head of this queue, or <tt>null</tt> if this queue is empty. |
467 |
> |
* @return the head of this list, or <tt>null</tt> if this list is empty. |
468 |
|
* @since 1.5 |
469 |
|
*/ |
470 |
|
public E poll() { |
475 |
|
|
476 |
|
/** |
477 |
|
* Retrieves and removes the head (first element) of this list. |
478 |
< |
* @return the head of this queue. |
479 |
< |
* @throws NoSuchElementException if this queue is empty. |
478 |
> |
* @return the head of this list. |
479 |
> |
* @throws NoSuchElementException if this list is empty. |
480 |
|
* @since 1.5 |
481 |
|
*/ |
482 |
|
public E remove() { |
497 |
|
|
498 |
|
// Deque operations |
499 |
|
/** |
500 |
< |
* Inserts the specified element to the front this deque. |
500 |
> |
* Inserts the specified element to the front of this list. |
501 |
|
* |
502 |
|
* @param e the element to insert |
503 |
|
* @return <tt>true</tt> (as per the spec for {@link Deque#offerFirst}) |
509 |
|
} |
510 |
|
|
511 |
|
/** |
512 |
< |
* Inserts the specified element to the end this deque. |
512 |
> |
* Inserts the specified element to the end of this list. |
513 |
|
* |
514 |
|
* @param e the element to insert |
515 |
|
* @return <tt>true</tt> (as per the spec for {@link Deque#offerLast}) |
521 |
|
} |
522 |
|
|
523 |
|
/** |
524 |
< |
* Retrieves, but does not remove, the first element of this deque, |
525 |
< |
* returning <tt>null</tt> if this deque is empty. |
524 |
> |
* Retrieves, but does not remove, the first element of this list, |
525 |
> |
* returning <tt>null</tt> if this list is empty. |
526 |
|
* |
527 |
< |
* @return the first element of this deque, or <tt>null</tt> if |
528 |
< |
* this deque is empty |
527 |
> |
* @return the first element of this list, or <tt>null</tt> if |
528 |
> |
* this list is empty |
529 |
|
* @since 1.6 |
530 |
|
*/ |
531 |
|
public E peekFirst() { |
535 |
|
} |
536 |
|
|
537 |
|
/** |
538 |
< |
* Retrieves, but does not remove, the last element of this deque, |
539 |
< |
* returning <tt>null</tt> if this deque is empty. |
538 |
> |
* Retrieves, but does not remove, the last element of this list, |
539 |
> |
* returning <tt>null</tt> if this list is empty. |
540 |
|
* |
541 |
< |
* @return the last element of this deque, or <tt>null</tt> if this deque |
541 |
> |
* @return the last element of this list, or <tt>null</tt> if this list |
542 |
|
* is empty |
543 |
|
* @since 1.6 |
544 |
|
*/ |
549 |
|
} |
550 |
|
|
551 |
|
/** |
552 |
< |
* Retrieves and removes the first element of this deque, or |
553 |
< |
* <tt>null</tt> if this deque is empty. |
552 |
> |
* Retrieves and removes the first element of this list, or |
553 |
> |
* <tt>null</tt> if this list is empty. |
554 |
|
* |
555 |
< |
* @return the first element of this deque, or <tt>null</tt> if |
556 |
< |
* this deque is empty |
555 |
> |
* @return the first element of this list, or <tt>null</tt> if |
556 |
> |
* this list is empty |
557 |
|
* @since 1.6 |
558 |
|
*/ |
559 |
|
public E pollFirst() { |
563 |
|
} |
564 |
|
|
565 |
|
/** |
566 |
< |
* Retrieves and removes the last element of this deque, or |
567 |
< |
* <tt>null</tt> if this deque is empty. |
566 |
> |
* Retrieves and removes the last element of this list, or |
567 |
> |
* <tt>null</tt> if this list is empty. |
568 |
|
* |
569 |
< |
* @return the last element of this deque, or <tt>null</tt> if |
570 |
< |
* this deque is empty |
569 |
> |
* @return the last element of this list, or <tt>null</tt> if |
570 |
> |
* this list is empty |
571 |
|
* @since 1.6 |
572 |
|
*/ |
573 |
|
public E pollLast() { |
577 |
|
} |
578 |
|
|
579 |
|
/** |
580 |
< |
* Pushes an element onto the stack represented by this deque. In other |
581 |
< |
* words, inserts the element to the front this deque. |
580 |
> |
* Pushes an element onto the stack represented by this list. In other |
581 |
> |
* words, inserts the element to the front this list. |
582 |
|
* |
583 |
|
* <p>This method is equivalent to {@link #addFirst}. |
584 |
|
* |
590 |
|
} |
591 |
|
|
592 |
|
/** |
593 |
< |
* Pops an element from the stack represented by this deque. In other |
594 |
< |
* words, removes and returns the the first element of this deque. |
593 |
> |
* Pops an element from the stack represented by this list. In other |
594 |
> |
* words, removes and returns the the first element of this list. |
595 |
|
* |
596 |
|
* <p>This method is equivalent to {@link #removeFirst()}. |
597 |
|
* |
598 |
< |
* @return the element at the front of this deque (which is the top |
599 |
< |
* of the stack represented by this deque) |
600 |
< |
* @throws NoSuchElementException if this deque is empty |
598 |
> |
* @return the element at the front of this list (which is the top |
599 |
> |
* of the stack represented by this list) |
600 |
> |
* @throws NoSuchElementException if this list is empty |
601 |
|
* @since 1.6 |
602 |
|
*/ |
603 |
|
public E pop() { |
606 |
|
|
607 |
|
/** |
608 |
|
* Removes the first occurrence of the specified element in this |
609 |
< |
* deque (when traversing the deque from head to tail). If the deque |
609 |
> |
* list (when traversing the list from head to tail). If the list |
610 |
|
* does not contain the element, it is unchanged. |
611 |
|
* |
612 |
< |
* @param e element to be removed from this deque, if present |
613 |
< |
* @return <tt>true</tt> if the deque contained the specified element |
612 |
> |
* @param e element to be removed from this list, if present |
613 |
> |
* @return <tt>true</tt> if the list contained the specified element |
614 |
|
* @since 1.6 |
615 |
|
*/ |
616 |
|
public boolean removeFirstOccurrence(Object e) { |
619 |
|
|
620 |
|
/** |
621 |
|
* Removes the last occurrence of the specified element in this |
622 |
< |
* deque (when traversing the deque from head to tail). If the deque |
622 |
> |
* list (when traversing the list from head to tail). If the list |
623 |
|
* does not contain the element, it is unchanged. |
624 |
|
* |
625 |
< |
* @param o element to be removed from this deque, if present |
626 |
< |
* @return <tt>true</tt> if the deque contained the specified element |
625 |
> |
* @param o element to be removed from this list, if present |
626 |
> |
* @return <tt>true</tt> if the list contained the specified element |
627 |
|
* @since 1.6 |
628 |
|
*/ |
629 |
|
public boolean removeLastOccurrence(Object o) { |