Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1.  
  2. public class LinkedList<E> {
  3.  
  4. private Node<E> head;
  5. private Node<E> tail;
  6. private int count;
  7.  
  8.  
  9. def boolean add(E e) {
  10. Node<E> node = new Node<>(e);
  11. if (head == null) {
  12. head = node
  13. tail = node
  14.  
  15. } else {
  16. tail.next = node
  17. tail = node
  18.  
  19. }
  20. count++
  21. return true
  22. }
  23.  
  24. def printAll() {
  25.  
  26. while (head != null) {
  27. println head.value
  28. head = head.next
  29. }
  30. }
  31.  
  32.  
  33. private class Node<E> {
  34. E value;
  35. public Node<E> next;
  36.  
  37. Node(E value) {
  38. this.value = value
  39. }
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement