public Node find(Bnode root, int key) { Bnode current = root; while (current != null) { int position = current.findPosition(key); if (position < current.n && current.keys[position] == key) { return(new Node(current, position)); //found } else { current = current.children[position]; } } return(null); //not found }
public List <int> getFindTraverseIndex(Bnode root, int key) { Bnode current = root; List <int> searchTraverseIndex = new List <int>(); while (current != null) { int position = current.findPosition(key); if (position < current.n && current.keys[position] == key) { if (current == this.root) { searchTraverseIndex.Add(-1); } return(searchTraverseIndex); //found } else { current = current.children[position]; searchTraverseIndex.Add(position); } } return(null); //not found }
public void insert(ref Bnode root, int key) { int currentDepth = 0; if (root == null) { root = new Bnode(m);//,0); root.insert(key); } else { Bnode current = root; while (true) { if (current.children[0] == null) //insert must be in leaf { int position = current.insert(key); while (current.n > current.size) //overflow //split the node { Object[] result = split(ref root, current, currentDepth); //try to insert middle key to parent Bnode newNode = (Bnode)result[0]; key = (int)result[1]; //separator current = current.parent; position = current.insert(key); current.children[position + 1] = newNode; } break; } current = current.children[current.findPosition(key)]; currentDepth++; } } }