-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.cpp
More file actions
executable file
·65 lines (54 loc) · 919 Bytes
/
tree.cpp
File metadata and controls
executable file
·65 lines (54 loc) · 919 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
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
//tree.cpp
//Max Smiley
//program # 3
//CS202
#include "tree.h"
//default constructor is the only one used. it creates an empty node object.
tree::tree()
{
root = new node();
}
//copy const
tree::tree(const tree& to_copy): root(to_copy.root) {}
//dest
tree::~tree()
{
delete root;
}
//assignment, as it is required when dynamic memory is used
tree& tree::operator=(const tree& to_copy)
{
if(this == &to_copy)
{
return *this;
}
if(root)
{
delete root;
}
root = new node(*to_copy.root);
return *this;
}
//adds an object, and checks to see if the root has changed.
void tree::add(Object & obj)
{
node * temp = root->add(&obj);
if(temp != root)
{
root = temp;
}
}
//prints some tree. used by stream insertion
void tree::print(ostream& out) const
{
if(root)
{
root->print(out, 0);
}
}
//overload insertion
ostream& operator<<(ostream& out, const tree& t)
{
t.print(out);
return out;
}