K******g 发帖数: 1870 | 1 写了个关于binary tree的代码,想测试一下。但是想来想去,不知道怎么随机生成一
棵binary tree,谁有什么好的建议吗?多谢。 |
h****8 发帖数: 599 | 2 你只需要随机生成节点的值,然后一个一个插入到树里面就行了呀 |
K******g 发帖数: 1870 | 3 怎么插到树里?关键不在于结点的值,而在于怎么写个方便的代码生成一棵树。
【在 h****8 的大作中提到】 : 你只需要随机生成节点的值,然后一个一个插入到树里面就行了呀
|
l*******r 发帖数: 511 | 4 生成一个随机数列不就可以了。。汗w
【在 K******g 的大作中提到】 : 怎么插到树里?关键不在于结点的值,而在于怎么写个方便的代码生成一棵树。
|
c**********n 发帖数: 516 | 5 The structure of a binary tree is fixed given the total number of nodes in
the tree, say N , so now you can easily construct the tree. I do not know
what is troubling you. perhaps you can post your code here, and we can tell
you what you need.
【在 K******g 的大作中提到】 : 怎么插到树里?关键不在于结点的值,而在于怎么写个方便的代码生成一棵树。
|
K******g 发帖数: 1870 | 6 就说给定一个N(结点的总数),depth也是随机的,每个结点的值是随机的。每次调用
这个函数,就要随机生成各种不同形状的树。即使对相同的N和depth,树的形状也有很
多种。
tell
【在 c**********n 的大作中提到】 : The structure of a binary tree is fixed given the total number of nodes in : the tree, say N , so now you can easily construct the tree. I do not know : what is troubling you. perhaps you can post your code here, and we can tell : you what you need.
|
a*****y 发帖数: 467 | 7 所以说生成一个随机数列,不断add不就行了。。。
【在 K******g 的大作中提到】 : 就说给定一个N(结点的总数),depth也是随机的,每个结点的值是随机的。每次调用 : 这个函数,就要随机生成各种不同形状的树。即使对相同的N和depth,树的形状也有很 : 多种。 : : tell
|