-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTNode.h
More file actions
38 lines (32 loc) · 802 Bytes
/
Copy pathBTNode.h
File metadata and controls
38 lines (32 loc) · 802 Bytes
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
#ifndef BTNODE_H_
#define BTNODE_H_
#include <sstream>
/** A node for a Binary Tree. */
template<typename Item_Type>
struct BTNode
{
// Data Fields
Item_Type data;
BTNode<Item_Type>* left;
BTNode<Item_Type>* right;
// Constructor
BTNode(const Item_Type& the_data,
BTNode<Item_Type>* left_val = NULL,
BTNode<Item_Type>* right_val = NULL) :
data(the_data), left(left_val), right(right_val) {}
// Destructor (to avoid warning message)
virtual ~BTNode() {}
// to_string
virtual std::string to_string() const {
std::ostringstream os;
os << data;
return os.str();
}
}; // End BTNode
// Overloading the ostream insertion operator
template<typename Item_Type>
std::ostream& operator<<(std::ostream& out,
const BTNode<Item_Type>& node) {
return out << node.to_string();
}
#endif