簡體   English   中英

if(;root){ 返回什么; c++ 中的意思

[英]What does if(!root){ return; } mean in c++

void printCodes(struct MinHeapNode* root, string str)
{
 
    if (!root)
        return;
 
    if (root->data != '$')
        cout << root->data << ": " << str << "\n";
 
    printCodes(root->left, str + "0");
    printCodes(root->right, str + "1");
}

if(root) 等價於if(root != nullptr) ,所以if(!root)代表if(root==nullptr)

[!!= -> ==]

 A precondition for almost every recursive function.

因此,當您收到nullptr根時,這意味着 function 到達了給定樹的末尾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM