Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@GGoYoungHee

Description

@GGoYoungHee
Issue body actions

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

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

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.