The seventh day of learning data structure (II)

  However, the law is just that I want to replace the currently feel that this replacement is also very consistent with it.

For me the kind of replacement method, how to do recursive calls, but also to see, thought recursive exercise, although it is not a good way.

  Real common alternative method:

 

Minimum maximum node node on the right position to be replaced or to be replaced on the left of the position, is commonly used method, but I picked a word, it is to take the smallest node in the right position to be replaced.

 

I use the alternative method, involves some knowledge of recursion in there, I also need to remove write about that approach.

key1: Note that the definition of this function: returns the root node after the deletion. (Reason: since the tree structure for the operation, its purpose below)

Suppose you want to do is: n n.left to replace it with a node n1 = n; n = n.left could it not?

 

 

 

 Process is actually occurring: node pointer, points to the current position from the position pointing node.left

 

Thus, the final inspiration: If you want to change the structure of the tree, the node A with the node B is replaced, it need to do is: root after it returns to the alternative, instead of changing the pointer.

Similarly thereto are: add function, add into a node tree which is also returned to it after replacement root, rather than that the pointer changes.

 

 

 

 So, you can understand why the above practices, rather than following the practice.

Because you are to be returned to its roots after the replacement, so the above approach, the root root root root is left after remove the right of the left, the right is after remove.

Grasping the connotation of the registration function.

 

The second point: the largest node, it may have left sub-tree (on the left are a series of lines, not only we can have a left child, because if it is small than the left subtree)

                The smallest nodes, you can have the right subtree (left side series will do, not only can have a left child, because if it is small than the left subtree)

 Here, then, if node M is deleted, then the deletion meaning: I.right = N, rather than that of the replacement pointer. If you say using a recursive method returns the root, then this needs to be saved to node I, node should also be used before a recording prev I, Node n1 M recording node, using prev.right = N to replace it.

 

 

 

 

Said here is: if you do not use the recursive method, How to delete prev thought some of the largest node, the smallest node.

 

Among them, the largest delete nodes, or delete nodes in minimum words.

 

 Here it is to say: the lowest node, there may be a right subtree. Directly take root right subtree of the current node to replace ok.

And if you remove common is: take the right subtree of the lowest node to replace it yourself , remember to replace their own, not the root right subtree.

Himself learned: how to delete the maximum node, the smallest idea how to delete nodes. And how to remove a node of ordinary thought.

How to see the size of the relationship after the replacement and original size relationship is in line with it?

 Need to delete the position above is certainly satisfied, need to delete the following positions is certainly satisfied, then just look at  the need to remove the interface position to meet the size of the relationship can be.

 

 

 

 Delete the smallest element, then the node E is actually deleted, to see whether the relationship between the size of the case, is to look at the relationship between H and D are not compliant.

Then H is greater than H and E must be less than D, then it is satisfied

 

That is, knows that the move is not satisfying to see how the size of the original relationship, look at the size of the interface position is not satisfying relationship can be.

And know how to remove the largest element, how to remove the smallest element, how to remove an element of the right way, and to realize my ideas.

The next chapter will realize these are written.

Guess you like

Origin www.cnblogs.com/startFrom0/p/12621304.html