Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 5639번 이진 검색 트리 (gold 5 본문
import java.io.*;
import java.util.*;
class Node{
int data;
Node left;
Node right;
public Node(int data, Node left, Node right){
this.data=data;
this.left=left;
this.right=right;
}
}
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Node root=new Node(Integer.valueOf(br.readLine()), null, null);
String input;
while((input=br.readLine())!=null && input.length()!=0){
in(root,Integer.valueOf(input));
}
find(root);
}
public static void in(Node temp, int a){
if(temp.data<a){
if(temp.right==null){
temp.right=new Node(a,null,null);
}
else{
in(temp.right,a);
}
}
else{
if(temp.left==null){
temp.left=new Node(a,null,null);
}
else{
in(temp.left,a);
}
}
}
public static void find(Node temp){
if(temp.left!=null){
find(temp.left);
}
if(temp.right!=null){
find(temp.right);
}
System.out.println(temp.data);
return;
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 1654번 랜선 자르기 (silver 2 (0) | 2023.10.16 |
---|---|
[백준] 11048번 이동하기 (silver 2 (0) | 2023.10.15 |
[백준] 1149번 RGB거리 (silver 1 (2) | 2023.10.14 |
[백준] 15686번 치킨 배달 (gold 5 (0) | 2023.10.13 |
[백준] 6571번 피보나치 수의 개수 (silver 3 (0) | 2023.10.13 |