-
Notifications
You must be signed in to change notification settings - Fork 0
/
treeNode.cc
68 lines (53 loc) · 1.36 KB
/
treeNode.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "treeNode.h"
#include <iostream>
TreeNode::TreeNode(std::string cntt): content {cntt} {}
// Returns content of node
std::string TreeNode::getContent() const {
return content;
}
// Returns left child node
TreeNode *TreeNode::getLeftChild() const {
return leftChild;
}
// Returns right child node
TreeNode *TreeNode::getRightChild() const {
return rightChild;
}
// Updates the left child node
void TreeNode::updateLeftChild(TreeNode *lChild) {
leftChild = lChild;
}
// Updates the right child node
void TreeNode::updateChildren(TreeNode *lChild, TreeNode *rChild) {
leftChild = lChild;
rightChild = rChild;
}
// Function to get node ID
int TreeNode::getID() const {
return id;
}
// Function to set node ID
void TreeNode::setID(int newID) {
if (id != -1) {throw "Error:";}
id = newID;
return;
}
OperatorNode::OperatorNode(std::string cntt): TreeNode{cntt} {}
// Returns false for non-variable treeNode
bool OperatorNode::isVariable() const {
return false;
}
ConstantNode::ConstantNode(std::string cntt): TreeNode{cntt} {}
// Returns false for non-variable treeNode
bool ConstantNode::isVariable() const {
return false;
}
VariableNode::VariableNode(std::string cntt): TreeNode{cntt} {}
// Returns true for variable treeNode
bool VariableNode::isVariable() const {
return true;
}
TreeNode::~TreeNode() {
delete leftChild;
delete rightChild;
}