Thanks to visit codestin.com
Credit goes to github.com

Skip to content

60번 삽입정렬 리스트 1번 풀이 질문 #168

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

Open
GGoYoungHee opened this issue Jul 5, 2023 · 1 comment
Open

60번 삽입정렬 리스트 1번 풀이 질문 #168

GGoYoungHee opened this issue Jul 5, 2023 · 1 comment

Comments

@GGoYoungHee
Copy link

GGoYoungHee commented Jul 5, 2023

안녕하세요!
책을 읽다가 헷갈리는 부분이 생겨 질문 드립니다.

p.501의 1번 풀이 중,
cur.next, head.next, head = head, cur.next, head.next
코드중, cur의 구조에 대해 이해가 가지 않아 책의 예제인 head가 4->2->1->3의 ListNode일 때를 구현해보았습니다.

cur의 변화를 print 해보니,
cur: None->4
cur: None->2->4 로 업데이트 되는 것을 확인하였습니다.

하지만 제 생각에는
cur: None->4
(이때 head: 2->1->3)
따라서 cur은 None->2->1->3이라고 생각했는데,

2->4가 어떤 방식으로, 어떻게 연결되는지 모르겠습니다.

감사합니다.

++ 추가: 해결했습니다!!
cur.next, head.next, head = head, cur.next, head.next

첫번째 루프
cur: None->4
head.next: None
head: 2->1->3

두번째 루프
cur.next=head =2->??
head.next=cur.next = 4
head=head.next = 1->3

다중할당이므로 다음과 같은 과정을 거치기 때문이라고 생각합니다!!

@likejazz
Copy link
Collaborator

파이썬의 다중 할당은 매우 편리하지만 반면 혼동하기 쉽기 때문에 신중하게 살펴봐야 합니다.
문제를 잘 해결하셨다니 다행이네요.
감사합니다.

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