-
Notifications
You must be signed in to change notification settings - Fork 0
/
tripletree_given.cpp
55 lines (51 loc) · 1.54 KB
/
tripletree_given.cpp
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
/**
* @file tripletree_given.h
* @description Instructor-provided implementation for given ternary
* tree functions for CPSC 221 PA3.
*
* THIS FILE WILL NOT BE MODIFIED/SUBMITTED FOR GRADING
*/
#include "tripletree.h"
/**
* TripleTree destructor.
* Destroys all of the memory associated with the
* current TripleTree. This function should ensure that
* memory does not leak on destruction of a TripleTree.
*
* @see TripleTree.cpp
*/
TripleTree::~TripleTree() {
Clear();
}
/**
* Copy constructor for a TripleTree.
* Since TripleTree allocate dynamic memory (i.e., they use "new", we
* must define the Big Three). This uses your implementation
* of the copy function.
* @see TripleTree.cpp
*
* @param other - the TripleTree we are copying.
*/
TripleTree::TripleTree(const TripleTree& other) {
Copy(other);
}
/**
* Overloaded assignment operator for TripleTree.
* Part of the Big Three that we must define because the class
* allocates dynamic memory. This uses your implementation
* of the copy and clear funtions.
*
* @param rhs - the right hand side of the assignment statement.
*/
TripleTree& TripleTree::operator=(const TripleTree& rhs) {
// only take action if this object is not living at the same address as rhs
// i.e. this and rhs are physically different trees
if (this != &rhs) {
// release any previously existing memory associated with this tree
Clear();
root = nullptr;
// and then copy the other tree
Copy(rhs);
}
return *this;
}