-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (78 loc) · 1.93 KB
/
main.cpp
File metadata and controls
82 lines (78 loc) · 1.93 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
#include <iostream>
#include "Tree.h"
using namespace std;
class Data {
public:
char label;
int estimate;
};
class Test {
public:
int a, b;
};
int main() {
linklist<Test> l;
auto *t1 = new Node<Test>;
l.add(t1);
Tree<Data> t;//define a Tree class
auto *a = new Node<Data>;//define Node
auto *b = new Node<Data>;
auto *c = new Node<Data>;
auto *d = new Node<Data>;
auto *e = new Node<Data>;
auto *f = new Node<Data>;
auto *g = new Node<Data>;
auto *h = new Node<Data>;
a->data->label = 'A';
a->cost = 0;
a->data->estimate = 0;
b->data->label = 'B';
b->cost = 6;
b->data->estimate = 2;
c->data->label = 'C';
c->cost = 4;
c->data->estimate = 5;
d->data->label = 'D';
d->cost = 1;
d->data->estimate = 12;
e->data->label = 'E';
e->cost = 5;
e->data->estimate = 8;
f->data->label = 'F';
f->cost = 2;
f->data->estimate = 4;
g->data->label = 'G';
g->cost = 3;
g->data->estimate = 1;
h->data->label = 'H';
h->cost = 6;
h->data->estimate = 0;
t.insert(a, nullptr);//insert a Node in Tree(root)
t.insert(c, a);//Right Node
t.insert(b, a);//Left Node
t.insert(g, c);//Right Node
t.insert(f, c);//Left Node
t.insert(e, b);//Right Node
t.insert(d, b);//Left Node
t.insert(h, g);//Right Node
Node<Data> *n;
cout << "DFS:" << endl;
dfs<Data> dfs(&t);
for (int i = 0; i < 8; i++) {
n = dfs.nextnode();
cout << n->data->label << endl;
}
cout << endl << "--------------------" << endl << "BFS:" << endl;
bfs<Data> bfs(&t);
for (int i = 0; i < 8; i++) {
n = bfs.nextnode();
cout << n->data->label << endl;
}
cout << endl << "--------------------" << endl << "A_Star:" << endl;
a_star<Data> a_star(&t);
for (int i = 0; i < 8; i++) {
n = a_star.nextnode();
cout << n->data->label << endl;
}
return 0;
}