Skip to content

Commit

Permalink
more functions...
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerrangerous committed May 15, 2017
1 parent 0c38ecb commit ec367fd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 4 deletions.
24 changes: 24 additions & 0 deletions 2-3-4_B_Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ int TwoThreeFourNode::GetNumItems()
return numItems;
}

int TwoThreeFourNode::FindItem(long key)
{
for (int i = 0; i <= ORDER - 1; i++)
{
if (dataItemArray[i] == nullptr)
{
// if dataItemArray[0] is nullptr, we are at a leaf and there will
// not be a dataItemArray[1]
break;
}
else if (dataItemArray[i]->data == key)
{
return dataItemArray[i]->data;
}
}

return -1;
}

void TwoThreeFourNode::DisplayNode()
{
for (int i = 0; i < numItems; i++)
Expand All @@ -143,4 +162,9 @@ bool TwoThreeFourNode::b_IsLeaf()
DataItem TwoThreeFourNode::GetItem(int index)
{
return *dataItemArray[index];
}

bool TwoThreeFourNode::b_IsFull()
{
return (numItems == ORDER - 1) ? true : false;
}
4 changes: 3 additions & 1 deletion 2-3-4_B_Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class TwoThreeFourNode

int InsertItem(DataItem* newItem);
int GetNumItems();
int FindItem(long key);
void DisplayNode();
bool b_IsLeaf();

bool b_IsFull();

DataItem GetItem(int index);


Expand Down
2 changes: 2 additions & 0 deletions 2-3-4_B_Tree_Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ int main()

node2.GetItem(1);

node2.FindItem(7);

return 0;
}

Binary file modified Debug/2-3-4_B_Tree.obj
Binary file not shown.
4 changes: 1 addition & 3 deletions Debug/2-3-4_B_Tree_Project.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
 2-3-4_B_Tree_Project.cpp
2-3-4_B_Tree.cpp
Generating Code...
 2-3-4_B_Tree.cpp
c:\users\brian\onedrive\documents\visual studio 2015\projects\2-3-4_b_tree_project\2-3-4_b_tree_project\2-3-4_b_tree.cpp(112): warning C4715: 'TwoThreeFourNode::GetChild': not all control paths return a value
2-3-4_B_Tree_Project.vcxproj -> C:\Users\Brian\onedrive\documents\visual studio 2015\Projects\2-3-4_B_Tree_Project\Debug\2-3-4_B_Tree_Project.exe
2-3-4_B_Tree_Project.vcxproj -> C:\Users\Brian\onedrive\documents\visual studio 2015\Projects\2-3-4_B_Tree_Project\Debug\2-3-4_B_Tree_Project.pdb (Full PDB)
Binary file modified Debug/2-3-4_B_Tree_Project.obj
Binary file not shown.
Binary file modified Debug/vc140.idb
Binary file not shown.
Binary file modified Debug/vc140.pdb
Binary file not shown.

0 comments on commit ec367fd

Please sign in to comment.