-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.h
88 lines (60 loc) · 1.79 KB
/
Graph.h
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
#ifndef _GRAPH_H
#define _GRAPH_H
#include "Graph.h"
#include "Vertex.h"
#include "UnionFind.h"
#include "Edge.h"
#include "Heap.h"
#include "Node.h"
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <list>
using namespace std;
class Graph{
private:
int numOfVert;
int numOfEdges;
// usado no algoritimo de kruskall
vector< Edge > edges;
// usado no algoritmo de prim
vector< Vertex* > vertices;
// used to color the subgraphs and on prims algoritm
vector< list< Vertex* > > adjlist;
public:
Graph();
Graph( vector< Vertex* > v );
~Graph();
//Add all the vertex written in the sousce file
void addVertex( FILE* source );
//Receives coordinates of a point and add a single vertex.
void addVertex( double a, double b );
//Receives index of two vertex and add an edge between than. Since it does not get the edge's weight
//it puts the distance as weight
void addEdge( int ind, int ind2 );
// rebuilds graph acording to a new list od edges
void addEdge( vector<Edge> vet );
//Returns number os vertices created
int getNumOfVertex();
int getNumOfEdges(){ return this->numOfEdges; }
private:
//Uses dfs as a way to color all the vertex. Its keept as private since its an auxiliary method for color method.
void dfs( Vertex* vert, int color );
public:
//Pinta os componentes conexos do grafo com "cores" diferentes
int color();
void clearAdjacencyList();
//Print colors(classes) from all vertex.
void printColors();
void printColors(FILE* fp );
//Creates minimim spanning tree acording to kruskall's algorithm
vector<Edge> kruskall( int );
//Creates minimim spanning tree acording to prim's algorithm
vector<Edge> prim();
double primsum();
void addEdge( Vertex*, Vertex* );
void clear();
int connectedComponents();
};
#endif