강의

멘토링

커뮤니티

Inflearn Community Q&A

sdyeob10024541's profile image
sdyeob10024541

asked

Jeong Hye-kyung Fantastic Data Structure in C

Lecture 25. Hash (Hash table) Implementation

DeleteHash함수와 destroyHash함수에 대해서 질문이 있습니다!

Written on

·

149

0

DeleteHash함수에서 매개변수로 int *dData를 주었는데

최종적으로 DeleteHash함수를 종료하기 전까지 *dData를 안했는데 해야하는 거 맞을까요 ..?

그리고 destroyHash함수에서 제가 짠 코드는 강사님의 코드와 조금 달랐는데 혹시 논리적 오류가 없는지 봐주실 수 있으실까요 ? 

제가 짠 destroy Hash 함수입니다!

void destroyHash(CHash *hsp) 
{
    if(hsp == NULL)
        return ;
    
    int i;
    Node *np = NULL;
    if(hsp->hash != NULL) 
        for(i = 0; i < hsp->size; i++)
        {
            if(hsp->hash[i].next != NULL)
            {
                while(hsp->hash[i].next != NULL)
                {
                    np = hsp->hash[i].next;
                    hsp->hash[i].next = np->next;
                    free(np);
                }
            }
        }
    
    free(hsp->hash); // 댕글링 포인터 
    hsp->hash = NULL;
    hsp->size = 0;
    hsp->dataCnt = 0;
}

 

추가로 혹시 자료들은 어디서 다운받아야 하는지 알 수 있을까요? 홈페이지에서 열심히 찾아봤는데 못찾았습니다 ㅠㅠ

c

Answer

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

asked

Ask a question