Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "LeafNode.h"
- #include "InternalNode.h"
- #include "QueueAr.h"
- using namespace std;
- LeafNode::LeafNode(int LSize, InternalNode *p,
- BTreeNode *left, BTreeNode *right) : BTreeNode(LSize, p, left, right)
- {
- values = new int[LSize];
- } // LeafNode()
- int LeafNode::getMinimum()const
- {
- if(count > 0) // should always be the case
- return values[0];
- else
- return 0;
- } // LeafNode::getMinimum()
- LeafNode* LeafNode::insert(int value)
- {
- // students must write this
- //If no room left in the array
- if (isFull())
- {
- //Check if theres room in the left sibling
- if ((leftSibling != NULL) && (!leftSibling->isFull()))
- {
- leftSibling->insert(); //If there is insert into it
- }
- //Check if theres room in the right sibling
- else if ((leftSibling != NULL) && (!leftSibling->isFull()))
- {
- rightSibling->insert(); //If there is insert into it
- }
- else
- {
- //Create a pointer and create a new node and put the bigger half of the elements into it
- }
- }
- //Else there is room left in the array
- else
- {
- //Go through the array and find the spot to put it into
- insertIntoArray(value);
- }
- return NULL; // to avoid warnings for now.
- } // LeafNode::insert()
- void LeafNode::insertIntoArray(int insert_value)
- {
- int array_holdcount;
- for(int array_count =0 ; array_count<count;array_count++)
- {
- if(insert_value < values[array_count]){
- int valueToPush = values[array_count];
- values[array_count] = insert_value;
- insert_value= valueToPush;
- array_holdcount = array_count;
- }
- }
- for (int array_count = array_holdcount; array_count < count; array_count++)
- {
- int valueToPush = values[array_count];
- values[array_count] = insert_value;
- insert_value= valueToPush;
- }
- value[array_count] = insert_value;
- }
- int LeafNode::takeLeast(int newVal)
- {
- //If the new value is the least value, just return it
- if (newVal <= *values[0])
- {
- return newVal;
- }
- //Else if the first element of the array is the least value
- else
- {
- //Save the least value from the array
- int leastVal = *values[0];
- for (int i = 0; i < count; i++)
- {
- }
- }
- }
- void LeafNode::takeGreatest(int newInt)
- {
- }
- bool LeafNode::isFull()
- {
- if (count >= leafSize)
- {
- return true;
- }
- return false;
- }
- void LeafNode::print(Queue <BTreeNode*> &queue)
- {
- cout << "Leaf: ";
- for (int i = 0; i < count; i++)
- cout << values[i] << ' ';
- cout << endl;
- } // LeafNode::print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement