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

Latest commit

 

History

History
History
31 lines (28 loc) · 857 Bytes

File metadata and controls

31 lines (28 loc) · 857 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ch08
import datatype.ListNode
class P18_2 {
fun oddEvenList(head: ListNode?): ListNode? {
// 예외 처리
if (head == null)
return null
// 홀수 노드
var odd: ListNode = head
// 짝수 노드
var even = head.next
// 짝수 첫 번째 노드
val evenHead = even
// 반복하면서 홀짝 노드 처리
while (even?.next != null) {
// 홀짝 노드의 다음 노드로 다음 다음 노드 지정
odd.next = odd.next.next
even.next = even.next.next
// 홀짝 한 칸씩 진행
odd = odd.next
even = even.next
}
// 홀수 노드 마지막을 짝수 첫 번째와 연결
odd.next = evenHead
// 첫 번째 노드 리턴
return head
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.