-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteriorNode.cpp
174 lines (144 loc) · 4.01 KB
/
InteriorNode.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
@file InteriorNode.cpp
@brief Implementation of InteriorNode class
@author Brandon Theisen, Jason Pederson, Kelvin Shultz, Chris, Jared
*/
#include "InteriorNode.h"
#include <vector>
#include <iostream>
using namespace std;
//-----CONSTRUCTOR-----\\
/**Default Constructor for InteriorNode
@post Creates a interiorNode*/
template<class T>
InteriorNode<T>::InteriorNode()
{
Node<T>::capacity = 6;
//Node<T>::Node();
//capacity = 6; //6 is default
//Default Constructor
}
//-----CONSTRUCTOR WITH CAPACITY-----\\
/**Default Constructor for Node with capacity
@pre Accepts a capacity for a node, depending on what type of node is being created
@param cap: capacity of the size in the node
@post Creates a base Node for either a leaf node or a interior node with a capacity*/
template<class T>
InteriorNode<T>::InteriorNode(int cap)
{
Node<T>::capacity = cap;
}
//-----COPY CONSTRUCTOR-----\\
/**Copy constructor that copies the node that calls it
@pre Accepts a node to be copied
@param Node to be copied
@post Copies the node that called the constructor*/
template<class T>
InteriorNode<T>::InteriorNode(const Node<T>& newCopy)
{}
//-----GET CHILD SIZE-----\\
/**Get size of the node
@post Returns the size of the node*/
template<class T>
int InteriorNode<T>::getChildSize()
{
return children.size();
}
//-----GET CHILD-----\\
/**Returns the child where the key located
@param key: key to be searched for
@post Returns the node where the key is located*/
template<class T>
Node<T>* InteriorNode<T>::getChild(int key)
{
return children.at(searchKey(key));
}
//-----SET CHILD-----\\
/**Sets the child of a node
@pre Called onto a interior node
@param newChild: The child to be set
@param position: Position of the node
@post Set the child to the node which is being called by*/
template<class T>
void InteriorNode<T>::setChild(Node<T>* newChild, int position)
{
children.insert(children.begin() + position, newChild);
}
//-----REMOVE CHILD-----\\
//All removes of children must be accompanied by a removal of a key
template<class T>
void InteriorNode<T>::removeChild(int position)
{
children.erase(children.begin() + position);
}
//-----SEARCH KEY-----\\
/**Searches for a key in a node
@pre Called from a interior node
@param key: The key to be searched for
@post Returns the position of the key*/
template<class T>
int InteriorNode<T>::searchKey(int key)
{
for(int i = 0; i < Node<T>::keys.size(); i++)
{
if(key <= Node<T>::keys.at(i))
{
return i;
}
}
return Node<T>::keys.size();
}
//-----ADD NEW KEY-----\\
/**Add a key
@pre Node must have room for the new key. size() <= capacity
@param newKey: key that will be entered
@post Return true or false on if the key was successfully added*/
template<class T>
int InteriorNode<T>::addKey(int newKey)
{
//return true;
return Node<T>::addKey(newKey);
}
//-----REMOVE KEY-----\\
/**Remove a key
@pre Key must be located in the node
@param position: Location of the key in the vector
@post Removes the key from the vector*/
template<class T>
void InteriorNode<T>::removeKey(int position)
{
Node<T>::keys.erase(Node<T>::keys.begin() + position);
}
//-----SPLIT-----\\
/**Split node
@param newNodePtr: Pointer to the new node that is being created
@post Splits the node by placing half of the key into a new node*/
template<class T>
void InteriorNode<T>::split(Node<T>* &newNodePtr)
{
Node<T>::split(newNodePtr);
}
//-----MERGE-----\\
/**Merge two nodes together
@param otherNodePtr: Pointer of the node the be merged with
@post Merges the two nodes together, placing all keys into the original node*/
template<class T>
void InteriorNode<T>::mergeNodes(Node<T>* &otherNodePtr)
{
Node<T>::mergeNodes(otherNodePtr);
}
//-----DESTRUCTOR-----\\
//
template<class T>
InteriorNode<T>::~InteriorNode()
{
//Destructor
}
/*--These functions are implemented in Node.cpp
//
int getSize();
Node<T>* getParent();
void setParent(Node<T>* newParentPtr);
int getKeyAt(int position);
bool contains(int key);
*/