root current leftchildelse if(isleftchild/left child of parent parent leftchild current leftchildelse /right child of parent parent rightchild current leftchild/if no left childreplace with right subtree else if(current leftchild==nullif(current =rootroot current rightchildelse if(isleftchild/left child of parent parent leftchild current rightchildelse /right child of parent parent rightchild current rightchild/continued notice that working with references makes it easy to move an entire subtree you do this by simply disconnecting the old reference to the subtree and creating new reference to it somewhere else although there may be lots of nodes in the subtreeyou don' need to worry about moving them individually in factthey "moveonly in the sense of being conceptually in different positions relative to the other nodes as far as the program is concernedonly the reference to the root of the subtree has changed case the node to be deleted has two children now the fun begins if the deleted node has two childrenyou can' just replace it with one of these childrenat least if the child has its own children why notexamine figure and imagine deleting node and replacing it with its right subtreewhose root is which left child would havethe deleted node' left child or the new node' left child in either case would be in the wrong placebut we can' just throw it away we need another approach the good news is that there' trick the bad news is thateven with the trickthere are lot of special cases to consider remember that in binary search tree the nodes are arranged in order of ascending keys for each nodethe node with the next-highest key is called its inorder successoror simply its successor in figure anode is the successor of node here' the trickto delete node with two childrenreplace the node with its inorder successor figure shows deleted node being replaced by its successor notice that the nodes are still in order (there' more to it if the successor itself has childrenwe'll look at that possibility in moment