-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.h
More file actions
76 lines (74 loc) · 1.31 KB
/
Node.h
File metadata and controls
76 lines (74 loc) · 1.31 KB
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
69
70
71
72
73
74
75
76
#pragma once
#ifndef NODE_H_
#define NODE_H_
template<class T>
class Node
{
public:
Node(){_left=NULL;_right=NULL;_height=0;}
Node(const T &data)
{
_data = data;
_left=NULL;
_right=NULL;
_height = 0;
}
virtual ~Node()
{
}
T &GetNodeContents(){return _data;}
Node *GetLeft(){return _left;}
Node *GetRight(){return _right;}
void SetLeftChild(Node *child){_left = child;}
void SetRightChild(Node *child){_right = child;}
void SetNodeContents(T data){_data = data;}
bool IsChildless()
{
if(_left==NULL&&_right==NULL)
return true;
else
return false;
}
bool IsFull()
{
if(_left!=NULL&&_right!=NULL)
return true;
else
return false;
}
Node** IsChild(T candidate)
{
Node **child = NULL;
bool matchLeft = IsChild(candidate,_left);
bool matchRight;
if(matchLeft==true)
child = &_left;
else
{
matchRight = IsChild(candidate,_right);
if(matchRight==true)
child = &_right;
}
return child;
}
static bool IsChild(T candidate, Node *child)
{
bool match = false;
if(child!=NULL)
{
if(candidate==child->GetNodeContents())
match = true;
}
return match;
}
int GetHeight(){return _height;}
void SetHeight(int hf){_height = hf;}
void IncHeight(){_height++;}
void DecHeight(){_height--;}
protected:
Node *_left;
Node *_right;
T _data;
int _height;
};
#endif