Advertisement
Guest User

Jacob Senpai Halp Me pt 2.

a guest
Mar 27th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // Elements used in implementation of doubly linked lists.
  2.  
  3. public class DListNode
  4. {
  5. private Object value;
  6. private DListNode next;
  7. private DListNode previous;
  8.  
  9. // Constructor:
  10. public DListNode(Object initValue,
  11. DListNode initNext,
  12. DListNode initPrevious)
  13. // post: constructs new element with list
  14. // prefix referenced by previous and
  15. // suffix referenced by next
  16. {
  17. value = initValue;
  18. next = initNext;
  19. if (next != null)
  20. next.previous = this;
  21. previous = initPrevious;
  22. if (previous != null)
  23. previous.next = this;
  24. }
  25.  
  26. public DListNode(Object initValue)
  27. // post: constructs a single element
  28. {
  29. this(initValue, null, null);
  30. }
  31.  
  32. public Object getValue()
  33. // post: returns value stored here
  34. {
  35. return value;
  36. }
  37.  
  38. public DListNode getNext()
  39. // post: returns the element that follows this
  40. {
  41. return next;
  42. }
  43.  
  44. public DListNode getPrevious()
  45. // post: returns element that precedes this
  46. {
  47. return previous;
  48. }
  49.  
  50. public void setValue(Object theNewValue)
  51. // post: sets a new value for this object
  52. {
  53. value = theNewValue;
  54. }
  55.  
  56. public void setNext(DListNode theNewNext)
  57. // post: sets value associated with this element
  58. {
  59. next = theNewNext;
  60. }
  61.  
  62. public void setPrevious(DListNode theNewPrevious)
  63. // post: establishes a new reference to a previous value
  64. {
  65. previous = theNewPrevious;
  66. }
  67.  
  68. public String toString()
  69. // post: returns string representation of element
  70. {
  71. return "[ " + getValue() + "]";
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement