#ifndef GRAPH_LIST_H_INCLUDED
#define GRAPH_LIST_H_INCLUDED
#include<iostream>
#include<queue>
#include<stack>
using std::cout;
using std::cin;
using std::endl;
#define GRAPH_LIST_H_INCLUDED
#include<iostream>
#include<queue>
#include<stack>
using std::cout;
using std::cin;
using std::endl;
struct Edge
{
friend class Graph_List;
Edge(int ver, int w, Edge* e = NULL){ VerAdj = ver; cost = w; link = e; }
int VerAdj;/*链接顶点序列,从0开始编号*/
int cost;/*边的权值*/
Edge* link;/*指向下一个节点的指针*/
{
friend class Graph_List;
Edge(int ver, int w, Edge* e = NULL){ VerAdj = ver; cost = w; link = e; }
int VerAdj;/*链接顶点序列,从0开始编号*/
int cost;/*边的权值*/
Edge* link;/*指向下一个节点的指针*/
};
struct Vertex
{
friend class Graph_List;
int VerName;/*顶点的头指针*/
Edge* adjacent;/*边链表的头指针*/
};
{
friend class Graph_List;
int VerName;/*顶点的头指针*/
Edge* adjacent;/*边链表的头指针*/
};
class Graph_List
{
private:
Vertex *Head;/*顶点链表的头指针*/
int graphsize;/*图中当前顶点的个数*/
int MaxGraphSize;
public:
Graph_List(int MaxSize = 100) :MaxGraphSize(MaxSize),Head(NULL){};
~Graph_List();
void CreatGraph();/*图的构建*/
int GetWeight(const int& v1, const int& v2);/*返回权值*/
void InsertEdge(const int& v1, const int& v2);/*插入边*/
void DeleEdge(const int& v1, const int& v2);/*删除边*/
int GetFirstNeighbor(const int &v);/*顶点v的第一个链接顶点*/
int GetNextNeighbor(const int& v1, const int& v2);/*顶点v的下一个个链接顶点*/
void REDF(const int& v, int* visited);/*深度遍历的递归实现*/
void DepthFirstSearch();/*深度遍历*/
void BFS(const int& s);/*广度遍历*/
void Show();/*测试函数,show图的边及顶点*/
void DShortestPath(const int& v);/*Djkstra算法*/
};
void Graph_List::CreatGraph()
{
int e;
int from, to, weight;
Head = new Vertex[MaxGraphSize];
cout << "请输入顶点个数:";
cin >> graphsize;
for (int i = 0; i<graphsize; i++)
{
Head[i].VerName = i;
Head[i].adjacent = NULL;
}
cout << "请输入边的条数:";
cin >> e;
for (int i = 0; i<e; i++)
{
cout << "请输入新边的始点ÿ
{
int e;
int from, to, weight;
Head = new Vertex[MaxGraphSize];
cout << "请输入顶点个数:";
cin >> graphsize;
for (int i = 0; i<graphsize; i++)
{
Head[i].VerName = i;
Head[i].adjacent = NULL;
}
cout << "请输入边的条数:";
cin >> e;
for (int i = 0; i<e; i++)
{
cout << "请输入新边的始点ÿ