Advertisement
Guest User

Node.cpp

a guest
Apr 30th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. /* Node.cpp */
  2. /* last modified: 4/18/2014 */
  3.  
  4.  
  5. #include<iostream>
  6. #include<stdlib.h>
  7.  
  8. #include "Node.h"
  9.  
  10. // ======================================================================
  11. Node::Node()                    // Default CTOR
  12. {
  13.     this->Qthing = DEFAULT_TEXT;
  14.  
  15.     this->left  = 0;            //make left and right point to NULL
  16.     this->right = 0;
  17.  
  18. }// CTOR
  19.  
  20. // ======================================================================
  21. Node::Node(const string text)   // CTOR when text is known
  22. {
  23.     this->Qthing = text;
  24.     this->left  = 0;            // make left and right point to NULL
  25.     this->right = 0;
  26.  
  27. }// CTOR
  28.  
  29. // ======================================================================
  30. Node::Node(const Node& old)     // COPY CTOR
  31. {
  32.     this->Qthing = old.Qthing;
  33.  
  34.     this->left  = old.left;     // new copy still points to the same children!
  35.     this->right = old.right;
  36.  
  37. }// COPY CTOR
  38.  
  39. // ======================================================================
  40. Node::~Node()   // DTOR
  41. {
  42.     // Tree DTOR does the work ...
  43.  
  44. }
  45.  
  46.  
  47. // ======================================================================
  48. // ---------- SETTERS ------------------------
  49.  
  50. void Node::StoreText(const string /*in*/ newText)
  51. {
  52.     this->Qthing = newText;
  53.  
  54. }// StoreText
  55.  
  56. // ======================================================================
  57. void Node::AppendRight(Node* /*in*/ newNode)
  58. {
  59.     this->right= newNode;
  60.  
  61.  
  62. }// AppendRight
  63.  
  64.  
  65. // ======================================================================
  66. void Node::AppendLeft(Node* /*in*/ newNode)
  67. {
  68.  
  69.     this ->left= newNode;
  70.  
  71. }// AppendLeft
  72.  
  73.  
  74. // ======================================================================
  75. // ---------- GETTERS ------------------------
  76.  
  77. string Node::GetText() const
  78. {
  79.     return this->Qthing;        // return the text of current node
  80. }// GetText
  81.  
  82.  
  83. // ======================================================================
  84. Node* Node::LChild() const
  85. {
  86.     return this->left;
  87.  
  88.  
  89. }// LChild
  90.  
  91.  
  92. // ======================================================================
  93. Node* Node::RChild() const
  94. {
  95.  
  96.     return this->right;
  97.  
  98. }// RChild
  99.  
  100.  
  101. // ======================================================================
  102. bool Node::IsLeaf() const
  103. {
  104.     if (this-> right == 0 && this-> left == 0)
  105.         return true;
  106.     else
  107.         return false;
  108.  
  109.  
  110.  
  111. }// IsLeaf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement