Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LinkedList<E> {
- private Node<E> head;
- private Node<E> tail;
- private int count;
- def boolean add(E e) {
- Node<E> node = new Node<>(e);
- if (head == null) {
- head = node
- tail = node
- } else {
- tail.next = node
- tail = node
- }
- count++
- return true
- }
- def printAll() {
- while (head != null) {
- println head.value
- head = head.next
- }
- }
- private class Node<E> {
- E value;
- public Node<E> next;
- Node(E value) {
- this.value = value
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement