grand->color redifitem element !item element parent rotateitemgrand )/start dbl rotate current rotateitemgreat )current->color blackheader->right->color black/make root black void insertconst comparable current parent grand headernullnode->element xwhilecurrent->element ! great grandgrand parentparent currentcurrent element current->left current->right/check if two red childrenfix if so ifcurrent->left->color =red &current->right->color =red handlereorientx )/insertion fails if already present ifcurrent !nullnode returncurrent new redblacknodexnullnodenullnode }/attach to parent ifx element parent->left currentelse parent->right currenthandlereorientx )figure (continuedotherwise one of ' children is red in this casewe fall through to the next levelobtaining new xtand if we're luckyx will land on the red childand we can continue onward if notwe know that will be redand and will be black we can rotate and pmaking ' new parent redx and its grandparent willof coursebe black at this pointwe can go back to the first main case