Java Reference
In-Depth Information
8 */
9 public class LinkedList<E>
10 {
11 /**
12 Constructs an empty linked list.
13 */
14 public LinkedList()
15 {
16 first = null ;
17 }
18
19 /**
20 Returns the first element in the
linked list.
21 @return the first element in the
linked list
22 */
23 public E getFirst()
24 {
25 if (first == null )
26 throw new NoSuchElementException();
27 return first.data;
28 }
29
30 /**
31 Removes the first element in the
linked list.
32 @return the removed element
33 */
34 public E removeFirst()
35 {
36 if (first == null )
37 throw new NoSuchElementException();
38 E element = first.data;
39 first = first.next;
40 return element;
41 }
42
43 /**
44 Adds an element to the front of the
linked list.
45 @param element the element to add
46 */
770
771
Search WWH ::




Custom Search