简体   繁体   中英

How to divide an object of class "Binary Search Tree" into two objects of class "Binary Search Tree"?

Class "Binary search tree". Complete the class by including the division method object of class "Binary search tree" on two objects of the class "Binary tree search ". The key to division must be the value of the item being requested software and is passed as an argument method. Items smaller than the key in value, should be placed in the first tree as well elements, and larger - in the second.


Just trying to put an algorithm around the question, may be it helps to get the requirement more clear

//your initial object is obj; you have [root,left,right] in your object; assign your left sub-tree to the new first object;

obj1=obj.left;

//then set the left sub-tree of your initial object to NULL

obj.left=NULL;

//assign remaining tree to new second object

obj2=obj;

Will that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM