Skip to content

Commit

Permalink
fix: answer-> 지역변수로 변경, 초기값 Null
Browse files Browse the repository at this point in the history
  • Loading branch information
JBumLee committed Sep 24, 2023
1 parent 0cc857d commit e080485
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/nhnacademy/jungbum/Quiz3.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
*/
public class Quiz3 {
private final Logger logger = LoggerFactory.getLogger(Quiz3.class);
ListNode answer = new ListNode(0);


/***
* 새로운 노드 4개생성후 연결
*/
public Quiz3() {
ListNode answer = new ListNode();
ListNode listNode1 = new ListNode(15);
ListNode listNode2 = new ListNode(10);
ListNode listNode3 = new ListNode(3);
Expand All @@ -24,7 +25,7 @@ public Quiz3() {
listNode2.setNext(listNode3);
listNode3.setNext(listNode4);

reverse(listNode1).setNext(new ListNode());
reverse(listNode1,answer).setNext(new ListNode());
while (answer.getListNode() != null) {
logger.info("{}", answer.getItem());
answer = answer.getListNode();
Expand All @@ -36,14 +37,14 @@ public Quiz3() {
* @param head 연결리스트 시작
* @return 완성된 연결리스트 + 뒤집기 시작한 연결리스트
*/
public ListNode reverse(ListNode head) {
public ListNode reverse(ListNode head,ListNode answer) {

if (head.getListNode() == null) {
answer = new ListNode(head.getItem());
// logger.info("{}",head.getItem());
return answer;
} else {
ListNode tmp = reverse(head.getListNode());
ListNode tmp = reverse(head.getListNode(),answer);
tmp.setNext(head);
return tmp.getListNode();
}
Expand Down

0 comments on commit e080485

Please sign in to comment.