我遇到了一个问题,说明
For each node in a binary search tree,
create a new duplicate node, and insert
the duplicate as the left child of the original node.
The resulting tree should still be a binary search tree.
http://cslibrary.stanford.edu/110/BinaryTrees.html
那里有解决方案,但我的解决方案不同。
void doubleTree(struct node* node) {
struct node* tempNode;
if (node->left == NULL)
{
node->left = new Node(node->data);
}
else{
tempNode = new Node(node->data);
tempNode->left = node->left;
node->left = tempNode;
}
}
这种方法正确吗?谢谢 。