1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
35 class LinkedListNode {
\r
39 public LinkedListNode next = null;
\r
43 public LinkedListNode prev = null;
\r
47 public Object item = null;
\r
51 * A very simple linked list.
\r
53 public class LinkedList {
\r
55 private LinkedListNode _head;
\r
56 private LinkedListNode _tail;
\r
59 * Create a new, empty linked list.
\r
61 public LinkedList() {
\r
62 _head = new LinkedListNode();
\r
63 _tail = new LinkedListNode();
\r
70 * Get the size of the list.
\r
72 * @return list size.
\r
79 * Add the given object at the end of the list.
\r
84 public void addLast(Object obj) {
\r
85 LinkedListNode node = new LinkedListNode();
\r
88 node.prev = _tail.prev;
\r
89 node.prev.next = node;
\r
90 node.next.prev = node;
\r
95 * Remove and return the first object of the list.
\r
97 * @return removed object.
\r
98 * @throws RuntimeException
\r
101 public Object removeFirst() {
\r
103 throw new RuntimeException("List empty");
\r
104 LinkedListNode node = _head.next;
\r
106 node.next.prev = _head;
\r
107 _head.next = node.next;
\r