-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
56 lines (46 loc) · 1.03 KB
/
Copy pathtest.cpp
File metadata and controls
56 lines (46 loc) · 1.03 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
49
50
51
52
53
54
55
56
#include "kruskal.h"
#include "prim.h"
#include "fibonacci.h"
#include <stdlib.h>
#include <string.h>
void Usage() {
printf("\nUsage: mst <algorithm> <graph_file> [<root_node>]\n");
printf("\t<algorithm> := ( kruskal | bprim | fprim )\n\n");
}
int main(int argc, char* argv[]) {
if (argc < 3) {
Usage();
return 1;
}
// Load the graph file.
FILE* f = fopen(argv[2], "rt");
if (f == NULL) {
printf("\nError reading file %s\n\n", argv[2]);
return 1;
}
tGraph* g = new tGraph();
g->Read(f);
fclose(f);
// Parse the given tree root.
int root;
if (argc >= 3)
root = atoi(argv[2]);
else
root = 0;
tGraph* tree = NULL;
if (strcmp(argv[1], "kruskal") == 0)
tree = KruskalSpanningTree(g);
else if (strcmp(argv[1], "bprim") == 0)
tree = BinomialPrimSpanningTree(g, root);
else if (strcmp(argv[1], "fprim") == 0)
tree = FibonacciPrimSpanningTree(g, root);
else {
delete g;
Usage();
return 1;
}
tree->Write(stdout);
delete tree;
delete g;
return 0;
}