반응형
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | package java8; public class Node { public Node next; public Node prev; private String value; public Node(String value) { this.value = value; } public Node() { } public String getValue() { return value; } public void setValue(String value) { this.value = value; } } package java8; import java.util.Scanner; public class MainClass { public static void main(String args[]) { System.out.print("값을 입력하세요. : "); Scanner in = new Scanner(System.in); Node parentNode = new Node(in.next()); Node curr = parentNode; StringBuilder str = new StringBuilder(); while (true) { System.out.print("값을 입력하세요. : "); String input = in.next(); if (input.equals("-1")) { break; } Node node = new Node(input); curr.next = node; node.prev = curr; curr = node; } curr = parentNode; while (true) { System.out.print(curr.getValue() + " "); if (curr.next == null) break; curr = curr.next; } System.out.println(); while (curr != null) { System.out.print(curr.getValue() + " "); if (curr.prev == null) break; curr = curr.prev; } } } | cs |
반응형
'JAVA > 알고리즘' 카테고리의 다른 글
정렬알고리즘 - 선택정렬 (0) | 2018.05.28 |
---|---|
10진수 2진수 변환 (0) | 2018.05.28 |
백준 1924 - 요일 맞추기 (0) | 2018.05.28 |
백준 2839 - 설탕 배달 (0) | 2018.05.28 |
선택정렬, 버블정렬, 삽입정렬 예제 (0) | 2016.12.22 |