ListNode.cpp 688 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "ListNode.h"
  2. // constructor with 0 parameters
  3. ListNode::ListNode() :
  4. ListNode(nullptr, nullptr)
  5. {
  6. }
  7. // constructor with 2 parameters
  8. ListNode::ListNode(void * data, ListNode * next) :
  9. data(data), next(next)
  10. {
  11. }
  12. // Destructor
  13. ListNode::~ListNode()
  14. {
  15. // delete the data it holds only
  16. delete data;
  17. }
  18. // set data the data for this node
  19. void ListNode::set_data(void * data)
  20. {
  21. this->data = data;
  22. }
  23. // get data the data in this node
  24. void * ListNode::get_data(void)
  25. {
  26. return this->data;
  27. }
  28. // set next the node
  29. void ListNode::set_next(ListNode * next)
  30. {
  31. this->next = next;
  32. }
  33. // get the next node
  34. ListNode * ListNode::get_next(void)
  35. {
  36. return this->next;
  37. }