-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBSTNode.cpp
More file actions
32 lines (28 loc) · 929 Bytes
/
BSTNode.cpp
File metadata and controls
32 lines (28 loc) · 929 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
//simple binary tree node implementation
template <typename Key, typename E>
class BSTNode : public BinNode<E>
{
private:
Key k;
E it;
BSTNode* lc;
BSTNode* rc;
public:
//two constructors -- with and without initial values
BSTNode() {lc=rc=NULL;}
BSTNode(Key K, E e, BSTNode * l=NULL, BSTNode* r=NULL)
{k=K; it = e; lc = l; rc = r;}
~BSTNode() {}
//functions to set and return the value and key
E& element() {return it;}
void setElement(const E& e) {it =e;}
Key& key() {return k;}
void setKey(constKey& K) {k=K;}
//functions to set and return the children
inline BSTNode* left() const {return lc;}
void setLeft(BinNode<E>* b) {lc = (BSTNode*)b;}
inline BSTNode* right() const {return rc;}
void setRight(BinNode<E>* b) {rc = (BSTNode*)b;}
//return true if it is a leaf, false otherwise
boll isLeaf() {return (lc==NULL) && (rc==NULL);}
};