Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0607_CSTree/CSTree.cpp中第48行和52行是否能省略if判断 #41

Open
sunrise0307 opened this issue Oct 25, 2024 · 0 comments
Open

Comments

@sunrise0307
Copy link

sunrise0307 commented Oct 25, 2024

https://github.com/kangjianwei/Data-Structure/blob/master/Dev-C%2B%2B/CourseBook/0607_CSTree/CSTree.cpp
//提问者认为在此函数中在42-44行已经有判断树是否存在的算法,第48行和52行判断长子树和兄弟树是否存在的算法是冗余的,不知是否可以去掉?

Status ClearTree(CSTree* T) {
    if(T == NULL) {
        return ERROR;
 }

// 在*T不为空时进行递归清理
if(*T) {
    if((*T)->firstchild != NULL) {
        ClearTree(&((*T)->firstchild));
    }
    
    if((*T)->nextsibling != NULL) {
        ClearTree(&((*T)->nextsibling));
    }
    
    free(*T);
    *T = NULL;
}

return OK;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant