Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 992a946

Browse filesBrowse files
committed
KrusKal算法
1 parent 6afa3d4 commit 992a946
Copy full SHA for 992a946

File tree

Expand file treeCollapse file tree

4 files changed

+11
-28
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+11
-28
lines changed
Open diff view settings
Collapse file

‎.idea/misc.xml‎

Copy file name to clipboardExpand all lines: .idea/misc.xml
+4-21Lines changed: 4 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎src/com/zejian/structures/Graph/WeightGraph/Edge.java‎

Copy file name to clipboardExpand all lines: src/com/zejian/structures/Graph/WeightGraph/Edge.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public Edge(int v, int w, Weight weight) {
1818

1919
public Edge(Edge<Weight> e)
2020
{
21-
this.v = e.w;
22-
this.w = e.w;
23-
this.weight = e.weight;
21+
this.v = e.v();
22+
this.w = e.w();
23+
this.weight = e.wt();
2424
}
2525

2626
/**
Collapse file

‎src/com/zejian/structures/Graph/WeightGraph/KruskalMST.java‎

Copy file name to clipboardExpand all lines: src/com/zejian/structures/Graph/WeightGraph/KruskalMST.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public KruskalMST(WeightGraph graph){
6363
//计算最小生成树的总权值
6464
mstWeight = mst.get(0).wt().doubleValue();
6565
for (int i = 1; i < mst.size() ; i++) {
66-
mstWeight =mstWeight.doubleValue() + mst.get(0).wt().doubleValue();
66+
mstWeight =mstWeight.doubleValue() + mst.get(i).wt().doubleValue();
6767
}
6868
}
6969

Collapse file

‎src/com/zejian/structures/Graph/WeightGraph/WeightSparseGraph.java‎

Copy file name to clipboardExpand all lines: src/com/zejian/structures/Graph/WeightGraph/WeightSparseGraph.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public void addEdge(Edge e) {
4141
assert e.v() >= 0 && e.v() < V ;
4242
assert e.w() >= 0 && e.w() < V ;
4343

44-
g[e.v()].add(e);
44+
g[e.v()].add(new Edge<Weight>(e));
4545
if( e.v() != e.w() && !directed ) {
46-
g[e.w()].add(e);
46+
g[e.w()].add(new Edge<Weight>(e.w(),e.v(), (Weight) e.wt()));
4747
}
4848
E++;
4949
}
@@ -89,7 +89,7 @@ public void show(){
8989
* @param args
9090
*/
9191
public static void main(String[] args){
92-
String filename = "weighttestG3.txt";
92+
String filename = "testWG1.txt";
9393

9494
WeightSparseGraph<Double> weightSparseGraph = new WeightSparseGraph<>(8,false);
9595
weightSparseGraph.readGraph(filename);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.