forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path7.java
More file actions
48 lines (36 loc) ยท 1.23 KB
/
7.java
File metadata and controls
48 lines (36 loc) ยท 1.23 KB
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
import java.util.*;
class Node {
private int index;
private int distance;
public Node(int index, int distance) {
this.index = index;
this.distance = distance;
}
public void show() {
System.out.print("(" + this.index + "," + this.distance + ") ");
}
}
public class Main {
// ํ(Row)์ด 3๊ฐ์ธ ์ธ์ ๋ฆฌ์คํธ ํํ
public static ArrayList<ArrayList<Node>> graph = new ArrayList<ArrayList<Node>>();
public static void main(String[] args) {
// ๊ทธ๋ํ ์ด๊ธฐํ
for (int i = 0; i < 3; i++) {
graph.add(new ArrayList<Node>());
}
// ๋
ธ๋ 0์ ์ฐ๊ฒฐ๋ ๋
ธ๋ ์ ๋ณด ์ ์ฅ (๋
ธ๋, ๊ฑฐ๋ฆฌ)
graph.get(0).add(new Node(1, 7));
graph.get(0).add(new Node(2, 5));
// ๋
ธ๋ 1์ ์ฐ๊ฒฐ๋ ๋
ธ๋ ์ ๋ณด ์ ์ฅ (๋
ธ๋, ๊ฑฐ๋ฆฌ)
graph.get(1).add(new Node(0, 7));
// ๋
ธ๋ 2์ ์ฐ๊ฒฐ๋ ๋
ธ๋ ์ ๋ณด ์ ์ฅ (๋
ธ๋, ๊ฑฐ๋ฆฌ)
graph.get(2).add(new Node(0, 5));
// ๊ทธ๋ํ ์ถ๋ ฅ
for (int i = 0; i < 3; i++) {
for (int j = 0; j < graph.get(i).size(); j++) {
graph.get(i).get(j).show();
}
System.out.println();
}
}
}