Skip to content

Commit 653d6e9

Browse files
committed
implemented minWeight()
1 parent b355a0b commit 653d6e9

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

src/Graph.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import java.io.File;
22
import java.io.FileNotFoundException;
3-
import java.util.Scanner;
3+
import java.util.*;
44

55
public class Graph implements Cloneable {
6-
6+
77
private int[][] edgeWeights;
88
private int size;
99
private String filename;
1010
private int maxWeight;
11-
11+
private int minWeight;
12+
1213
public Graph(String filename) throws FileNotFoundException {
1314
this.filename = filename;
1415
File file = new File(filename);
@@ -25,13 +26,20 @@ public Graph(String filename) throws FileNotFoundException {
2526
}
2627
scanner.close();
2728
maxWeight = 0;
29+
minWeight = -1;
2830
// for each element in the input, do fancy things
2931
int x = 0, y = 0, z = 0;
3032
for (String i : scannedString.split(",")) {
3133
int weight = Integer.parseInt(i);
32-
if(weight>maxWeight){
34+
if(minWeight==-1){
35+
minWeight = weight;
36+
}
37+
if (weight > maxWeight) {
3338
maxWeight = weight;
3439
}
40+
if (weight < minWeight){
41+
minWeight = weight;
42+
}
3543
if (x == y) {
3644
x++;
3745
}
@@ -45,25 +53,25 @@ public Graph(String filename) throws FileNotFoundException {
4553
}
4654
}
4755
}
48-
56+
4957
public Graph(int size, int[][] edgeWeights) {
5058
this.size = size;
5159
this.edgeWeights = edgeWeights;
5260
}
53-
61+
5462
public int weight(int from, int to) {
5563
return edgeWeights[from][to];
5664
}
57-
65+
5866
public int[][] matrix() {
5967
return edgeWeights;
6068
}
61-
69+
6270
public void deleteNode(int node) {
6371
// delete a node from the graph, along with all incoming and outgoing
6472
// edges
6573
}
66-
74+
6775
public Graph clone() {
6876
int[][] cloneWeights = new int[size][size];
6977
for (int i = 0; i < size; i++) {
@@ -73,7 +81,7 @@ public Graph clone() {
7381
}
7482
return new Graph(size, cloneWeights);
7583
}
76-
84+
7785
public void PrintEdgeWeights() {
7886
String out = "";
7987
for (int[] row : edgeWeights) {
@@ -84,34 +92,39 @@ public void PrintEdgeWeights() {
8492
}
8593
System.out.println(out);
8694
}
87-
95+
8896
public String getFilename() {
8997
return filename;
9098
}
91-
92-
99+
100+
public void setFilename(String filename) {
101+
this.filename = filename;
102+
}
103+
104+
93105
public int[][] getEdgeWeights() {
94106
return edgeWeights;
95107
}
96-
108+
97109
public void setEdgeWeights(int[][] edgeWeights) {
98110
this.edgeWeights = edgeWeights;
99111
}
100-
112+
101113
public int getSize() {
102114
return size;
103115
}
104-
116+
105117
public void setSize(int size) {
106118
this.size = size;
107119
}
108-
109-
public void setFilename(String filename) {
110-
this.filename = filename;
111-
}
112120

113121
public int getMaxWeight() {
114122
return maxWeight;
115123
}
116-
124+
125+
public int getMinWeight() {
126+
return minWeight;
127+
}
128+
129+
117130
}

0 commit comments

Comments
 (0)