⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphtest.cpp

📁 里面包含各种数据结构方面的知识,如链表,树,图等 含有vc代码
💻 CPP
字号:
#include <conio.h>
typedef char VerT;
typedef char datatype;		
#include "AdjMWGraph.h"
#include "Floyd.h"
#include "GraphLib.h"

template <class T>
void Make2DArray(T** &a, int row, int col)
//定义二维动态数组a,其行数为row, 列数为col
{
	a = new T*[row];			//a为有row个指针的指针数组

	for(int i = 0; i < row; i++)
	{
		a[i] = new T[col];		//每个指针指向一个有col个元素空间的数组
	}
}

void main(void)
{
	AdjMWGraph g;
	char a[] = {'A','B','C'};
	RowColWeight rcw[] = {{0,2,5},{2,1,6},{1,0,4},{0,1,12}};
	int n = 3, e = 4;

	CreatGraph(g, a, n, rcw, e);

	int m = g.NumOfVertices();
	int **distance, **path;
	Make2DArray<int>(distance, m, m);
	Make2DArray<int>(path, m, m);

	Floyd(g, distance, path);
/*
	int i, j, k;
	for(i = 0; i < m; i++)
	{
		cout << "从顶点" << g.GetValue(i) << "到其他各顶点的最短距离为:" << endl;
		for(j = 0; j < m; j++)
			cout << "到顶点 " << g.GetValue(j) 
				<< " 的最短距离为:" << distance[i][j] << endl;

		for(j = 0; j < m; j++)
		{
			cout << "从顶点" << g.GetValue(i) 
				<< "到顶点" << g.GetValue(j) << "的最短路径为:";
			for(k = 0; k < m; k++)
				if(path[i][k] != -1)
					cout << g.GetValue(path[i][k]) << "   ";
			cout << endl;
		}
		getch();
	}
*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -