porteno

Node

Dec 10th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1.  
  2. public class Node<T> {
  3. private T value;
  4. private Node<T> next;
  5.  
  6.  
  7. public Node(T value) {
  8. this.value = value;
  9. this.next = null;
  10. }
  11.  
  12.  
  13. public Node(T value, Node<T> next) {
  14. this.value = value;
  15. this.next = next;
  16. }
  17.  
  18. //return true if there is a next node
  19. public boolean hasNext() {
  20. return this.next != null;
  21. }
  22. public T getValue() {
  23. return value;
  24. }
  25.  
  26.  
  27. public void setValue(T value) {
  28. this.value = value;
  29. }
  30.  
  31.  
  32. public Node<T> getNext() {
  33. return next;
  34. }
  35.  
  36.  
  37. public void setNext(Node<T> next) {
  38. this.next = next;
  39. }
  40.  
  41.  
  42.  
  43. public String print() {
  44. return "value=" + value + ", next=" + next + " ";
  45. }
  46.  
  47.  
  48. }
Add Comment
Please, Sign In to add comment