Node * BST::insert_real(int key, Node *& node)
{
if (node == nullptr)
return node = new Node(key);
if (key < node->key)
return insert_real(key, node->left);
else if (key > node->key)
return insert_real(key, node->right);
else
return nullptr;
}
Node * BST::insert(int key)
{
return insert_real(key, header->left);
}
BinarySearchTree,插入函数。
如果key
总是left
,当函数insert_all()
运行到node = new Node(key)
位置时,node
是否等同于header->left->left->left->left->left->......->left->left
}?
如果我的上述猜测是正确的,则代码header->left->left->left->left->left->......->left->left
会带来一些负担。(如果是,我会将Node*&
替换为Node**
)
我上面说的话是对的吗?
答案 0 :(得分:0)
如果密钥总是向左移动,当函数insert_all()运行到位置node = new Node(key)时,该节点是否等同于header-&gt; left-&gt; left-&gt; left-&gt;左&GT;左&GT; ......-&GT;左&GT;左
不,在以下调用中,您不会更改收到的Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Dim bottomCell As Range
Dim rngTemp As Range
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 97-2003", "*.xlsx; *.xlsm; *.xlsa , *.xls"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set wkbSourceBook = ActiveWorkbook
Set bottomCell = wkbSourceBook.Sheets("par_ACCOUNT").Cells.Find(what:="Account by Type")
Set rngTemp = wkbSourceBook.Sheets("par_ACCOUNT").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Not rngTemp Is Nothing Then
Set rngSourceRange = wkbSourceBook.Sheets("par_ACCOUNT").Range(bottomCell, rngTemp.Offset(0, 65))
End If
Set rngDestination = wkbCrntWorkBook.Sheets("Tabelle1").Range("A1")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
wkbSourceBook.Close False
End If
End With
参数。您只是使用其他参数调用node
。
insert_real()
您更改return insert_real(key, node->left);
的唯一时间是
node