Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //~~~~~~~~~~~~~~~~~~~~~~FIND (And related helper methods)~~~~~~~~~~~~~~~~~~~~~
- public String find(int key) {
- Node curNode = root;
- int childNumber;
- while (true) {
- if ((childNumber = curNode.getRecordIndex(key)) != -1)
- return curNode.records[childNumber].data; // found it
- else if (curNode.isLeaf())
- return null; // can't find it
- else curNode = getNextChild(curNode, key);
- }
- }
- private Node getNextChild(Node theNode, long theValue) {
- int j;
- // assumes node is not empty, not full, not a leaf
- int numItems = theNode.numRecords;
- for (j = 0; j < numItems; j++)
- {
- if (theValue < theNode.records[j].key)
- return theNode.children[j];
- }
- return theNode.children[j];
- }
- //============================================================================
Add Comment
Please, Sign In to add comment