-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
124 lines (100 loc) · 2.81 KB
/
test.cpp
File metadata and controls
124 lines (100 loc) · 2.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include "test.h"
using namespace std;
int main(){
// make an undirected and connected graph
// remember n is vertices and m is edges
cout << "hello world";
FILE* pFile = fopen("input.txt", "r");
if(pFile == NULL){
cout << "Fam u can't do that stop";
return 0;
}
// read in first line with n and m
int n, m;
fscanf(pFile, "%d %d", &n, &m);
cout << "Settings: " << n << " " << m << endl;
int adj_mat[n][n];
struct graph* g = createGraph(n, m);
// iterate thru all edges
for(int i = 0; i<m; i++){
int n1, n2, weight;
fscanf(pFile, "%d %d %d", &n1, &n2, &weight);
// adjecency list nonsense
adj_mat[n1][n2] = weight; // put that node in
adj_mat[n2][n1] = weight; //gotta put it in for both
// disjoint unions
// TODO check the dereference
addEdge(&(g.edge[i]), n1, n2, weight);
}
// adjacency graph built now it's dumb lit
// okay fam lets get this bread with the normal sequential algorithm
return 0;
}
// a constructor in cpp??
struct graph* createGraph(int V, int E) {
graph* g = new graph;
g->V = V;
g->E = e;
g->edge = new edge[E];
return g;
}
// finds the set of an element
// TODO need to do more research on disjoint unions to know what that means
int find(struct subset subsets[], int i) {
// path compression??
// TODO find root and make root parent of i what
if(subsets[i].parent != i) {
subsets[i].parent = find(subsets, subsets[i].parent);
}
return subsets[i].parent;
}
// does the union of two sets of x and y
// (definition of above: Union by Rank)
// TODO what is union by rank
void Union(struct subset subsets[], int x, int y) {
int xroot = find(subsets, x);
int yroot = find(subsets, y);
// attach smaller rank tree under the root of the high rank tree
if (subsets[xroot].rank < subsets[yroot].rank) {
subsets[xroot].parent = yroot;
} else if (subsets[xroot].rank > subsets[yroot].rank) {
subsets[yroot].parent = xroot;
} else {
// if ranks are equal, make x root and increment rank by one
// TODO why increment rank by 1 only? what is rank?
subsets[yroot].parent = xroot;
subsets[xroot].rank++;
}
}
void addEdge(edge* e, int src, int dest, int weight) {
e.src = src;
e.dest = dest;
e.weight = weight;
}
void primMST(int graph[][]) {
}
void printMST(int n, int graph[][], int parent[]){
cout << " Edge \t Weight\n";
for(int i = 1)
}
void babushkaMST(struct graph* graph) {
int V = g->V;
int E = g->E;
edge *e = graph.edge;
//allocate memory for creating V subsets
// TODO what is a subset
// Michael, what. does a bean mean?
struct subset *subsets = new subset[V];
//stores the cheapest edge of each subset
int *cheapest = new int[V];
// create V subsets with single elements
for (int v = 0; v < V; ++v) {
subsets[v].parent = v;
subsets[v].rank = 0;
cheapest[v] = -1;
}
}