l*****a 发帖数: 14598 | 1 这种题需要新建Node吗?
还是说node.left 相当于 node.previous
node.right相当于node.next |
S******1 发帖数: 216 | 2
你太让我失望了....
【在 l*****a 的大作中提到】 : 这种题需要新建Node吗? : 还是说node.left 相当于 node.previous : node.right相当于node.next
|
l*****a 发帖数: 14598 | 3 请直接回答,谢谢
【在 S******1 的大作中提到】 : : 你太让我失望了....
|
S******1 发帖数: 216 | 4
不知道啊,不谢。。。
【在 l*****a 的大作中提到】 : 请直接回答,谢谢
|
f*******w 发帖数: 1243 | |
l*****a 发帖数: 14598 | 6 那就把binary tree的结构当成doubly linked list看?
【在 f*******w 的大作中提到】 : 一般问这个题都是不能新建node吧
|
s**x 发帖数: 7506 | 7 Yes. Google, you can find a lot of solutions online.
Stanford univ has a class paper for this.
The question is how to merger two binary search tree.
★ 发自iPhone App: ChineseWeb 8.7
【在 l*****a 的大作中提到】 : 那就把binary tree的结构当成doubly linked list看?
|
T*******e 发帖数: 4928 | 8 应该不需要。
void bstToDListHelper(Node *cur, Node *&head, Node *&pre){
if(!cur) return;
bstToDListHelper(cur->left, head, pre);
cur->left=pre;
if(pre){
pre->right=cur;
}else{
head=cur;
}
pre=cur;
bstToDListHelper(cur->right, head, pre);
}
Node *bstToDList(Node *root){
if(!root) return NULL;
Node *head=NULL, *pre=NULL;
bstToDListHelper(root, head, pre);
return head;
}
【在 l*****a 的大作中提到】 : 这种题需要新建Node吗? : 还是说node.left 相当于 node.previous : node.right相当于node.next
|
s**x 发帖数: 7506 | 9 http://www.geeksforgeeks.org/merge-two-balanced-binary-search-t
Method 3
★ 发自iPhone App: ChineseWeb 8.7
【在 s**x 的大作中提到】 : Yes. Google, you can find a lot of solutions online. : Stanford univ has a class paper for this. : The question is how to merger two binary search tree. : : ★ 发自iPhone App: ChineseWeb 8.7
|