#ifndef GRAPH_H
#define GRAPH_H
#include <iostream>
#include <cmath>
using namespace std;
const int UNVISITED = 0;
const int VISITED = 1;
class Edge {
public:
int from; //edge start point
int to; //edge end point
int weight; //edge weight
Edge() {
from = to = -1;
weight = 0;
}
Edge(int f, int t, int w) {
from = f;
to = t;
weight = w;
}
void print() {
cout<<"E"<<from<<"->"<<to<<" weight: "<<weight<<endl;
}
};
class Graph {
public:
int numVertex; // vertexs of graph
int numEdge; // edges of graph
int *Mark; // to sign vertex whether be visited
int *Indegree; // indegree of vertex
Graph(int numVert) {
numVertex = numVert;
numEdge = 0;
Indegree = new int[numVertex];
Mark = new int[numVertex];
for (int i = 0; i < numVertex; i++) {
Mark[i] = UNVISITED;
Indegree[i] = 0;
}
}
~Graph() {
delete []Mark;
delete []Indegree;
}
bool isEdge(Edge oneEdge) {
if (oneEdge.weight > 0 && oneEdge.weight < INFINITY && oneEdge.to >= 0)
return true;
else
return false;
}
};
#endif
graph.h
最新推荐文章于 2022-07-11 22:08:02 发布