Red property: Red nodes do not have red parents.
Black property*: Siblings have equal maximum black heights.
Enter up to 32 numbers between -9 and 99:
Insert
Delete
Next step...
|
Insertion algorithm
insert newNode and make it red.
if newNode violates red property
fixRed(newNode)
operation complete.
|
# fixMe is red and it has a red parent
function fixRed(fixMe)
if parent of fixMe is root
make root black, and we're all done.
if fixMe has a red uncle
make parent and uncle black,
and make grandparent red.
if grandparent violates red property
fixRed(grandparent)
else
# rotateUp changes color of outside child's parent.
# So, if fixMe is outside child, then
# rotateUp(parent of fixMe) fixes red violation.
if fixMe is not an outside child
rotateUp(fixMe)
fixMe = outsideChild(fixMe)
rotateUp(parent of fixMe).
|