View difference between Paste ID: j1BubAeE and tAXaurxz
SHOW: | | - or go back to the newest paste.
1
public class LinkedList<E> {
2
3
    private Node<E> head;
4
    private Node<E> tail;
5
    private int count;
6
7
8
    def boolean add(E e) {
9
        Node<E> node = new Node<>(e);
10
        if (head == null) {
11
            head = node
12
            tail = node
13
14
        } else {
15
            tail.next = node
16
            tail = node
17
18
        }
19
        count++
20
        return true
21
    }
22
23
    def printAll() {
24
25
        while (head != null) {
26
            println head.value
27
            head = head.next
28
        }
29
    }
30
31
32
    private class Node<E> {
33
        E value;
34
        public Node<E> next;
35
36
        Node(E value) {
37
            this.value = value
38
        }
39
40
    }
41
}