|
|
|
|
#pragma once
|
|
|
|
|
#define _stprintf
|
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
|
|
|
|
|
|
#include<iostream>
|
|
|
|
|
#include<fstream>
|
|
|
|
|
#include<graphics.h>
|
|
|
|
|
#include<string>
|
|
|
|
|
#define LEFTBORDER 30
|
|
|
|
|
#define TOPBORDER 50
|
|
|
|
|
|
|
|
|
|
// def edge class
|
|
|
|
|
class Edge {
|
|
|
|
|
private:
|
|
|
|
|
int VerAdj; // num of point
|
|
|
|
|
int cost; // weight of edge
|
|
|
|
|
Edge* link;
|
|
|
|
|
public:
|
|
|
|
|
Edge();
|
|
|
|
|
// initialization
|
|
|
|
|
Edge(int _veradj, int _cost, Edge* _link) : VerAdj(_veradj), cost(_cost), link(_link)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
int& get_VerAdj();
|
|
|
|
|
int& get_cost();
|
|
|
|
|
Edge*& get_link();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Vertex {
|
|
|
|
|
private:
|
|
|
|
|
std::string VerName;
|
|
|
|
|
std::string Description;
|
|
|
|
|
Edge* adjacent; // to neighbor
|
|
|
|
|
int mark; // NO
|
|
|
|
|
int x, y; // position
|
|
|
|
|
public:
|
|
|
|
|
// initialization
|
|
|
|
|
Vertex();
|
|
|
|
|
std::string& get_VerName();
|
|
|
|
|
std::string& get_Description();
|
|
|
|
|
Edge*& get_adjacent();
|
|
|
|
|
int& get_mark();
|
|
|
|
|
int& get_x();
|
|
|
|
|
int& get_y();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Graph_List {
|
|
|
|
|
private:
|
|
|
|
|
Vertex* head;
|
|
|
|
|
int graphsize; // summary of number of vertex
|
|
|
|
|
int MaxCost;
|
|
|
|
|
IMAGE* map;
|
|
|
|
|
int insert_edge_do(int v1, int v2, int weight) {
|
|
|
|
|
if (head[v1].get_adjacent() == NULL) {
|
|
|
|
|
head[v1].get_adjacent() = new Edge(v2, weight, NULL);
|
|
|
|
|
return 0; // <20><><EFBFBD>ڽӱ<DABD>Ϊ<EFBFBD>գ<EFBFBD>ֱ<EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD>±<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
Edge* p = head[v1].get_adjacent();
|
|
|
|
|
Edge* pt = p;
|
|
|
|
|
while ((p != NULL) && (p->get_VerAdj() < v2)) {
|
|
|
|
|
pt = p;
|
|
|
|
|
p = p->get_link();
|
|
|
|
|
}
|
|
|
|
|
if (p == NULL) {
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڽӱ<DABD>ĩ<EFBFBD><C4A9><EFBFBD>Ա<EFBFBD>v2С
|
|
|
|
|
pt->get_link() = new Edge(v2, weight, NULL);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (p == head[v1].get_adjacent() && p->get_VerAdj() > v2) { // <20>ڽӵ<DABD>һ<EFBFBD><D2BB><EFBFBD>ͱ<EFBFBD>v2<76><32>
|
|
|
|
|
Edge* q = new Edge(v2, weight, NULL);
|
|
|
|
|
q->get_link() = p;
|
|
|
|
|
head[v1].get_adjacent() = q;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (p->get_VerAdj() == v2) {
|
|
|
|
|
return -4; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>-4
|
|
|
|
|
}
|
|
|
|
|
if (p != head[v1].get_adjacent() && p->get_VerAdj() > v2) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽӱ<DABD><D3B1><EFBFBD>
|
|
|
|
|
Edge* q = new Edge(v2, weight, NULL);
|
|
|
|
|
pt->get_link() = q;
|
|
|
|
|
q->get_link() = p;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int delete_edge_do(int v1, int v2) {
|
|
|
|
|
Edge* p = head[v1].get_adjacent();
|
|
|
|
|
if (p == NULL) {
|
|
|
|
|
return -1; // <20><><EFBFBD><EFBFBD>-1<><31>ʾ<EFBFBD><CABE>ɾ<EFBFBD><C9BE><EFBFBD>ı߲<C4B1><DFB2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
if (p->get_VerAdj() == v2) { // <20>ڽӱ<DABD><D3B1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>v2
|
|
|
|
|
head[v1].get_adjacent() = p->get_link();
|
|
|
|
|
delete p;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
Edge* pt = p;
|
|
|
|
|
while (p) {
|
|
|
|
|
if (p->get_VerAdj() == v2) {
|
|
|
|
|
pt->get_link() = p->get_link();
|
|
|
|
|
delete p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pt = p;
|
|
|
|
|
p = p->get_link();
|
|
|
|
|
}
|
|
|
|
|
if (p == NULL) { // <20><><EFBFBD>ڽӱ<DABD>ĩ<EFBFBD><C4A9><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD>v2<76><32><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int delete_Graph_List() { // ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for (int i = 0; i < graphsize; i++) {
|
|
|
|
|
Edge* p = head[i].get_adjacent();
|
|
|
|
|
Edge* q = p;
|
|
|
|
|
while (p) {
|
|
|
|
|
p = p->get_link();
|
|
|
|
|
delete q;
|
|
|
|
|
q = p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete[] head;
|
|
|
|
|
delete map;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
int& get_MaxCost();
|
|
|
|
|
Vertex* get_head();
|
|
|
|
|
IMAGE* get_map();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
int get_index(int _mark);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
int get_index(std::string name);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͼ
|
|
|
|
|
int graph_con(std::fstream& file, char* mapname);
|
|
|
|
|
// <20><><EFBFBD>캯<EFBFBD><ECBAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͼ
|
|
|
|
|
Graph_List();
|
|
|
|
|
~Graph_List();
|
|
|
|
|
// <20><><EFBFBD>ؽڵ<D8BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int number_of_vertices()const;
|
|
|
|
|
// <20><><EFBFBD>رߵ<D8B1><DFB5><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
|
|
|
|
|
int number_of_edges()const;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
int save_file(char* filename);
|
|
|
|
|
bool is_graph_empty();
|
|
|
|
|
int get_weight(const int& v1, const int& v2);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
void insert_vertex(std::string _name, std::string _des, int _mark, int _x, int _y);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int insert_edge(int v1, int v2, int weight);
|
|
|
|
|
// ɾ<><C9BE><EFBFBD><EFBFBD>
|
|
|
|
|
int delete_edge(int v2, int v1);
|
|
|
|
|
// ɾ<><C9BE><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
int delete_vertex(const int& v);
|
|
|
|
|
// <20>Ľڵ<C4BD>Ԫ<EFBFBD><D4AA>
|
|
|
|
|
int modify_vertex(int v, std::string _n, std::string _des, int& _m, int& _x, int& _y);
|
|
|
|
|
int dshortest_path(const int v, int*& path);
|
|
|
|
|
// <20>·<EEB3A4><C2B7>
|
|
|
|
|
int dlongest_path(const int v, int*& path);
|
|
|
|
|
};
|