-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.h
More file actions
85 lines (64 loc) · 1.54 KB
/
Copy pathTree.h
File metadata and controls
85 lines (64 loc) · 1.54 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
77
78
79
80
81
82
83
84
85
/*
* Tree.h
*
* Created on: Apr 7, 2012
* Author: jason
*/
#include "Node.h"
#include <stdlib.h>
#ifndef TREE_H_
#define TREE_H_
template <class T, class S>
class Tree : public Node<S> {
public:
Tree(S* val);
virtual ~Tree();
void print();
void printClass();
void print(T* root, int depth);
void printClass(T* root, int depth);
};
template <class T, class S>
Tree<T,S>::Tree(S* val) : T(val) {
}
template <class T, class S>
Tree<T,S>::~Tree() {
//cout << "delete the tree" << endl;
}
template <class T, class S>
void Tree<T,S>::print() {
print((T*)this, 0);
}
template <class T, class S>
void Tree<T,S>::printClass() {
printClass((T*)this, 0);
}
template <class T, class S>
void Tree<T,S>::print(T* root, int depth) {
if (root == NULL) return;
cout << " d: " << depth;
if (root->parent)
cout << " parent: " << *(root->parent->getValue());
cout << " node: " << *(root->getValue());
T* temp = root->getChildren();
while (temp != NULL) {
print(temp, depth+1);
temp = temp->getNext();
}
cout << endl;
}
template <class T, class S>
void Tree<T,S>::printClass(T* root, int depth) {
if (root == NULL) return;
cout << "d: " << depth;
if (root->parent)
cout << " parent: " << (root->parent->getClassValue());
cout << endl;
cout << " node: " << (root->getClassValue()) << endl;
T* temp = root->getChildren();
while (temp != NULL) {
printClass(temp, depth+1);
temp = temp->getNext();
}
}
#endif /* TREE_H_ */