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

p.297 해시테이블 질문 #150

Open
Freemill opened this issue Feb 14, 2022 · 1 comment
Open

p.297 해시테이블 질문 #150

Freemill opened this issue Feb 14, 2022 · 1 comment

Comments

@Freemill
Copy link

Freemill commented Feb 14, 2022

안녕하세요. 해시테이블이 이해가 안돼 질문 드립니다.

아래의 Hash Table. put명령어를 보면
def(self, key:int, value: int) -> None:
---
---
---
#인덱스에 노드가 존재하는 경우 연결 리스트 처리
p = self.table[index]
while p:
if p.key == key:
p.value = value
return

   if p.next is None:     
       break                    

이 부분이 이해가 안됩니다. 이 부분을 추가한 이유가 아래에서 error가 나게 하지 않기 위함으로 설명이 되있는데
이 코드가 있으면 연결 리스트를 만들 수 없지 않나요? 지금 ListNode를 보면 next의 default 값이 None으로 설정 되어 있어서 항상 위 구문이 실행돼 메서드를 탈출하게 되는데 위 구문이 있게 된 이유가 이해가 안됩니다.

좋은 책 써주셔서 감사합니다.

@likejazz
Copy link
Collaborator

likejazz commented Mar 3, 2022

코드에 자세한 설명을 생략하다 보니 혼동을 드린거 같네요. 처음에는 바로 탈출하나 그 다음 부터는 p.next = ListNode(key, value)로 인해 한번 더 진행하게 됩니다.

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

2 participants