Java Reference
In-Depth Information
33 */
34 public Object removefirst()
35 {
36 if (first == null )
37 throw new NoSuchElementException();
38 Object 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 */
47 public void addfirst(Object element)
48 {
49 Node newNode = new Node();
50 newNode.data = element;
51 newNode.next = first;
52 first = newNode;
53 }
54
55 /**
56 Returns an iterator for iterating through this list.
57 @return an iterator for iterating through this list
58 */
59 public ListIterator listIterator()
60 {
61 return new LinkedListIterator();
62 }
63
64 private Node first;
65
66 private class Node
67 {
68 public Object data;
69 public Node next;
70 }
71
72 private class LinkedListIterator implements
ListIterator
73 {
678
679
Search WWH ::




Custom Search