티스토리 뷰
http://www.edwith.org/datastructure-2017f/lecture/13960/
마찬가지
package priortyQueue;
public class BinarySearchTree {
public static Node[] bst;
public static void main(String[] args) {
bst = new Node[mypow(5)];
enqueue("김대중", 10);
enqueue("박근혜", 3);
enqueue("노무현", 9);
enqueue("이명박", 9);
enqueue("문재인", 2);
inorderPrintTree(1);
}
private static int mypow(int i) {
int returnInt = 1;
for (int j = 0; j < i; j++) {
returnInt *= 2;
}
return returnInt;
}
private static void enqueue(String name, int priority) {
tree(name, priority, 1);
}
private static void tree(String name, int priority, int i) {
while (bst[i] != null) {
if (bst[i].Priority < priority) {
i = 2 * i;
} else {
i = 2 * i + 1;
}
}
bst[i] = new Node(name, priority);
}
public static void inorderPrintTree(int i) {
if (bst[i] == null) {
return;
}
inorderPrintTree(i * 2);
System.out.print(bst[i]);
inorderPrintTree(i * 2 + 1);
}
public static class Node {
String Name;
int Priority;
public Node(String name, int priority) {
Name = name;
Priority = priority;
}
public String toString() {
return "[" + Name + ", " + Priority + "]";
}
}
}
'알고리즘' 카테고리의 다른 글
priortyQueue (linked list) (0) | 2017.11.14 |
---|---|
java bufferedreader - 실행속도가 더 빠름 (0) | 2017.03.19 |
1065 한수 (0) | 2017.03.17 |
4673 셀프넘버 (0) | 2017.03.17 |
4344 평균은 넘겠지 (0) | 2017.03.17 |
- Total
- Today
- Yesterday
- 소인수분해
- java
- 1112
- 센서
- 1050
- 팀을위한GIT
- 소수
- 1143
- CH340G
- 등차수열
- 1111
- 1046
- 1104
- 1044
- 최대공약수
- acmicpc
- 1002
- 1045
- 시험후기
- OS설치
- 1124
- 챗봇
- 1110
- 최소공배수
- Git
- 1103
- 근의공식
- 1048
- ASCII
- 반올림
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |