Created
October 24, 2015 19:38
-
-
Save Baekjoon/a0fbbde7274d2c125fcd to your computer and use it in GitHub Desktop.
1991
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void preorder(int[][] a, int x) { | |
if (x == -1) return; | |
System.out.print((char)(x+'A')); | |
preorder(a,a[x][0]); | |
preorder(a,a[x][1]); | |
} | |
public static void inorder(int[][] a, int x) { | |
if (x == -1) return; | |
inorder(a,a[x][0]); | |
System.out.print((char)(x+'A')); | |
inorder(a,a[x][1]); | |
} | |
public static void postorder(int[][] a, int x) { | |
if (x == -1) return; | |
postorder(a,a[x][0]); | |
postorder(a,a[x][1]); | |
System.out.print((char)(x+'A')); | |
} | |
public static void main(String args[]) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
sc.nextLine(); | |
int[][] a = new int[26][2]; | |
for (int i=0; i<n; i++) { | |
String line = sc.nextLine(); | |
int x = line.charAt(0) - 'A'; | |
char y = line.charAt(2); | |
char z = line.charAt(4); | |
if (y == '.') { | |
a[x][0] = -1; | |
} else { | |
a[x][0] = y-'A'; | |
} | |
if (z == '.') { | |
a[x][1] = -1; | |
} else { | |
a[x][1] = z-'A'; | |
} | |
} | |
preorder(a,0); | |
System.out.println(); | |
inorder(a,0); | |
System.out.println(); | |
postorder(a,0); | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment