0

我需要将 bst 中的数据保存到排序数组中,然后,该ConvertToCompleteBST函数清除当前树并使用数组通过在每次调用中插入中间值来递归地重新插入值。

InsertRecursively(data_array,size);

例如,如果数组是 [5 7 10 12 16 18 30]

然后InsertRecursively([5 7 10 12 16 18 30],7)首先被调用,

中间是12所以 12 是第一个插入到树中的。然后在递归调用中,它会做同样的事情,但对于

InsertRecursively([5 7 10],3)
InsertRecursively([16 18 30],3)

然后,InsertRecursively([5 7 10],3)将导致插入节点7和另外两个递归调用

InsertRecursively([5],1) >> 导致插入节点 5

InsertRecursively([10],1)>> 导致插入节点 10

当 size 为 1 时,它将停止递归调用。

我不知道如何实现 insertRecursively 功能

4

0 回答 0