-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadjmatrix.h
More file actions
100 lines (83 loc) · 1.83 KB
/
adjmatrix.h
File metadata and controls
100 lines (83 loc) · 1.83 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
#ifndef ADJMATRIX_H
#define ADJMATRIX_H
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <utility>
#include <forward_list>
/**
* \class Matrix
*
* @brief The Graph class
*/
class adjMatrix
{
private:
/*
A int array beacause we have to store weights.
This array will be indexed ALWAYS with "long long"'s (refer to
.cpp to see it).
*/
double* data;
int* degrees;
int nVertices;
public:
/**
* @brief Graph Default constructor
*/
adjMatrix(){
data = NULL;
degrees = NULL;
nVertices = 0;
}
void generate(int numVertices);
void push(int x, int y, double w);
int degree(int v) const{return degrees[v];}
bool getNeighbours(int vertex, int** array) const{
int* draft;
*array = new int[degrees[vertex]];
draft = *array;
long long index = 0;
int counter = 0;
for(int i = 0; i<nVertices; i++){
if (vertex > i){
index = (((vertex+1)*vertex)/2)-vertex+i;
}
else{
index = (((i+1)*i)/2)-i+vertex;
}
if(data[index]!=-1){
draft[counter]=i;
counter++;
}
}
return true;
}
bool getWeights(int vertex, double** array) const{
double* draft;
*array = new double[degrees[vertex]];
draft = *array;
long long index = 0;
int counter = 0;
for(int i = 0; i<nVertices; i++){
if (vertex > i){
index = (((vertex+1)*vertex)/2)-vertex+i;
}
else{
index = (((i+1)*i)/2)-i+vertex;
}
if(data[index]!=-1){
draft[counter]=data[index];
counter++;
}
}
return true;
}
void postProcess();
~adjMatrix(){
if (data) delete [] data;
}
protected:
};
#endif // ADJLIST_H