Guest User

Untitled

a guest
Jan 23rd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. //~~~~~~~~~~~~~~~~~~~~~~FIND (And related helper methods)~~~~~~~~~~~~~~~~~~~~~
  2.     public String find(int key) {
  3.         Node curNode = root;
  4.         int childNumber;
  5.        
  6.         while (true) {
  7.             if ((childNumber = curNode.getRecordIndex(key)) != -1)
  8.                 return curNode.records[childNumber].data; // found it
  9.             else if (curNode.isLeaf())
  10.                 return null; // can't find it
  11.             else curNode = getNextChild(curNode, key);
  12.         }
  13.  
  14.     }
  15.    
  16.     private Node getNextChild(Node theNode, long theValue) {
  17.         int j;
  18.         // assumes node is not empty, not full, not a leaf
  19.         int numItems = theNode.numRecords;
  20.         for (j = 0; j < numItems; j++)
  21.         {
  22.             if (theValue < theNode.records[j].key)
  23.                 return theNode.children[j];
  24.         }
  25.         return theNode.children[j];
  26.     }
  27. //============================================================================
Add Comment
Please, Sign In to add comment