-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
57 lines (45 loc) · 949 Bytes
/
node.h
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
/**
* @author Thadeu <thadeutucci@gmail.com>
* @date 2019
* AST nodes.
*/
#pragma once
#include <iostream>
#include <memory>
using namespace std;
class ASTNode
{
public:
ASTNode() {};
virtual ~ASTNode() {};
// Print AST tree
void prettyPrint();
virtual int evaluate() = 0;
protected:
unique_ptr<ASTNode> leftNode;
unique_ptr<ASTNode> rightNode;
// Print node value
virtual void print() const = 0;
private:
// These are used for prettyPrint
int getHeight();
void printFloor(int floor, int indent);
};
class InternalNode : public ASTNode
{
public:
InternalNode(unique_ptr<ASTNode> _left, unique_ptr<ASTNode> _right, char _value);
int evaluate() override;
private:
char value;
void print() const override;
};
class LeafNode : public ASTNode
{
public:
LeafNode (char _value);
int evaluate() override;
private:
int value;
void print() const override;
};