Binary search tree: insert

From Algowiki
Revision as of 11:24, 13 September 2014 by Luedecke (talk | contribs) (Created page with "TREE-INSERT(T, z) :y = Null :x = root(T) :while x ≠ NULL ::y = x ::if key[z] < key[x] :::then x = left[x] :::then x = right[x] :p[z] = y :if y = NULL ::then root[T] = z //Tr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

TREE-INSERT(T, z)

y = Null
x = root(T)
while x ≠ NULL
y = x
if key[z] < key[x]
then x = left[x]
then x = right[x]
p[z] = y
if y = NULL
then root[T] = z //Tree was empty
else if key[z] < key[y]
then left[y] = z
else right[y] = z