n.children[key[i]]
is nil, fail.
n.children[key[i]]
.
(node, node, int) find'(parent, root, key, dno) if root = nil return (parent, root, dno) if root isa data-node return (parent, root.data = key ? root : nil, dno) return find'(root, root.children[key[dno]], key, dno + 1)
find()
is easy using find'()
:
bool find(root, key) (_, root, _) = find'(nil, root, key, 0) return root = nil
insert(root, key) (parent, root, dno) = find'(nil, root, key, 0) if root = nil parent.children[key[dno]] = new data-node(key)
delete(root, key) (parent, root, dno) = find'(nil, root, key, 0) if root ≠ nil while root.parent ≠ nil parent = root.parent free root parent.children[key[--dno]] = nil if parent.child_count() ≠ 0, break root = parent
123-45-6789
1234
123-45-6789$
1234$
(node, node, int)
find'(parent, root, key, dno)
if root = nil
return (parent, root, dno)
if root isa data-node
return (parent,
root.data = key ? root : nil,
dno)
if root.key = key
return (parent, root, dno)
return find'(root,
root.children[key[dno]],
key,
dno + 1)
(branch-node ref, key digit, child-node ref)