-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.cpp
More file actions
61 lines (51 loc) · 1.06 KB
/
Copy pathTree.cpp
File metadata and controls
61 lines (51 loc) · 1.06 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
// basic tree
#include<iostream>
#include<assert.h>
using namespace std;
template <class item>
class Node{
item data;
bool visited;
int NumOfChildren;
Node** children;
};
template <class item>
void preOrder(Node<item>* root)
{
root->visited = 1;
for(int i=0;i<root->NumOfChildren;i++)
preOrder(root->children[i]);
}
template <class item>
void postOrder(Node<item>* root)
{
for(int i=0;i<root->NumOfChildren;i++)
postOrder(root->children[i]);
root->visited = 1;
}
template <class item>
class Node2{
private:
item data;
bool visited;
int NumOfChildren;
Node2** children;
public:
Node2();
void preOrder();
void postOrder();
};
template <class item>
void Node2<item>::preOrder()
{
this->visited = 1;
for(int i=0;i<this->NumOfChildren;i++)
this->children[i]->preOrder();
}
template <class item>
void Node2<item>::postOrder()
{
for(int i=0;i<this->NumOfChildren;i++)
this->children[i]->postOrder();
this->visited = 1;
}