D:\Users\tomas\Documents\NetBeansProjects\PrikladGrafy\src\prikladgrafy\Graf.java |
1
2
3
4
5
6 package prikladgrafy;
7
8 import java.io.FileInputStream;
9 import java.io.FileNotFoundException;
10 import java.util.Scanner;
11
12
13
14 @author
15
16 public class Graf
17 {
18
19 int n;
20 int m;
21 int H[][];
22
23 public Graf(int paPocetVrcholov, int paPocetHran)
24 {
25 n = paPocetVrcholov;
26 m = paPocetHran;
27 H = new int[1 + m][3];
28 }
29
30
31
32
33
34
35
36
37 public static Graf nacitajSubor(String nazovSuboru)
38 throws FileNotFoundException
39 {
40
41 Scanner s = new Scanner(new FileInputStream(nazovSuboru));
42
43
44 int pocetVrcholov = 1;
45 int pocetHran = 0;
46
47 while (s.hasNext())
48 {
49
50 int u = s.nextInt();
51 int v = s.nextInt();
52 int c = s.nextInt();
53
54
55 pocetHran++;
56
57
58 if (pocetVrcholov < u) pocetVrcholov = u;
59 if (pocetVrcholov < v) pocetVrcholov = v;
60 }
61
62 s.close();
63
64
65 Graf g = new Graf(pocetVrcholov,pocetHran);
66
67
68
69 s = new Scanner(new FileInputStream(nazovSuboru));
70
71
72
73 for (int j = 1; j <= pocetHran; j++)
74 {
75 int u = s.nextInt();
76 int v = s.nextInt();
77 int c = s.nextInt();
78
79 g.H[j][0] = u;
80 g.H[j][1] = v;
81 g.H[j][2] = c;
82 }
83
84 return g;
85 }
86
87 public void printInfo()
88 {
89 System.out.println("Pocet vrcholov: " + n);
90 System.out.println("Pocet hran: " + m);
91 }
92
93 }
94