forked from onlybooks/java-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP15_1.java
More file actions
21 lines (18 loc) · 624 Bytes
/
P15_1.java
File metadata and controls
21 lines (18 loc) · 624 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package ch08;
import datatype.ListNode;
public class P15_1 {
public ListNode reverse(ListNode node, ListNode prev) {
// 현재 노드인 node가 널이면 리턴
if (node == null)
return prev;
// 현재 노드의 다음 노드 미리 지정
ListNode next = node.next;
// 현재 노드의 다음으로 이전 노드 지정
node.next = prev;
// 다음 노드와 현재 노드를 파라미터로 하여 재귀 호출
return reverse(next, node);
}
public ListNode reverseList(ListNode head) {
return reverse(head, null);
}
}