您的位置:首页 > 其它

graph.h

2015-07-26 19:40 141 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: