-
Notifications
You must be signed in to change notification settings - Fork 0
/
intStruct.h
97 lines (80 loc) · 1.98 KB
/
intStruct.h
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
86
87
88
89
90
91
92
93
94
95
96
97
//
// TreeObjects.h
// Binary Search Tree
//
// Created by Matt Burdumy on 10/21/12.
// Copyright 2012 Georgetown University. All rights reserved.
//
#ifndef Binary_Search_Tree_TreeObjects_h
#define Binary_Search_Tree_TreeObjects_h
using namespace std;
struct INT
{
public:
int * data;
INT(); // Default Constructor
INT(int); // Constructor
INT(INT const &input); // Copy Constructor
INT & operator=(INT const &rhs); // Overloading '=' operator.
bool operator==(const INT &rhs) const;// Overloading '==' operator.
bool operator<(const INT &rhs) const; // Overloading '<' operator.
bool operator>(const INT &rhs) const; // Overloading '>' operator.
~INT(); // Destructor
};
///// INT type functions defined below//////////////////////////////////
INT::INT() ////Default Constructor
{
data = new int;
}
INT::INT(INT const &input) // Copy Constructor
{
//cout<<"Copy Constructor Called"<<endl;
delete data;
data = new int;
*data = *(input.data);
}
INT::INT(int input) // Constructor
{
data = new int;
*data = input;
}
INT & INT::operator=(INT const &rhs) // Deep copy of pointers.
{
if (data == NULL) // Must allocate new memory
{
data = new int;
}
(*data) = *(rhs.data);
return *this;
}
bool INT::operator==(INT const &rhs) const
{
if (data==NULL && rhs.data == NULL) // Both are null
return true;
else if ( *data == *(rhs.data)) // They are equal return true.
return true;
else // They must not be equal
return false;
}
bool INT::operator<(INT const &rhs) const
{
if (*data < *(rhs.data))
return true;
else
return false;
}
bool INT::operator>(INT const &rhs) const
{
if (*data > *(rhs.data))
return true;
else
return false;
}
INT::~INT() // Destructor
{
//std::cout<<"Destructor Called"<<endl;
if (data == NULL) {} // do nothing
else
delete data;
}
#endif