-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjmatrix.cpp
55 lines (48 loc) · 882 Bytes
/
adjmatrix.cpp
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
#include "adjmatrix.h"
void adjMatrix::generate(int numVertices){
long long size = (numVertices*(numVertices-1))/2;
data = new double[size];
for(int i = 0; i<size; i++){
data[i] = -1.0;
}
nVertices = numVertices;
return;
}
void adjMatrix::push(int x, int y, double w){
long long index;
if (x > y){
index = (((x+1)*x)/2)-x+y;
data[index] = w;
}
else{
index = (((y+1)*y)/2)-y+x;
data[index] = w;
}
return;
}
void adjMatrix::postProcess(){
degrees = new int[nVertices];
int size = 0;
long long index;
for(int x = 0; x<nVertices; x++){
size = 0;
for(int y = 0; y<nVertices; y++){
if(x != y){
if (x > y){
index = (((x+1)*x)/2)-x+y;
if(data[index]>0.0) {
size++;
}
}
else{
index = (((y+1)*y)/2)-y+x;
if(data[index]>0.0){
size++;
}
}
}
}
degrees[x]=size;
}
return;
}