강의

멘토링

커뮤니티

Inflearn Community Q&A

sdyeob10024541's profile image
sdyeob10024541

asked

Jeong Hye-kyung Fantastic Data Structure in C

31st Lecture. BSTree Feature Implementation (delete2)

delete 코드에서 질문이 2개 있습니다!

Written on

·

176

0

질문 1. 

while문에서 parent의 값을 넣어주는데 밑 코드에서 parent의 초기값을 tp->root로 주는 이유가 궁금합니다. 

초기값을 parent = NULL;로 주어도 똑같을까요?

 

parent = del = tp->root;
    while(del != NULL) 
    {
        if(data == del->data)
            break;
        parent = del;
        if(data < del->data)
            del = del->left;
        else
            del = del->right;
    } 

질문 2.

if(del != NULL)
    {
        free(del);
        --tp->nodeCnt;
        return del;
    }
    else
        return NULL;

 

해당 코드의 윗부분에서 이미 

if(del == NULL)

 return NULL;

이라는 코드가 존재하는데 밑에서 한번 더 검사하는 이유를 잘 모르겠습니다.

c

Answer

This question is waiting for answers
Be the first to answer!
sdyeob10024541's profile image
sdyeob10024541

asked

Ask a question