graphtest.cpp

来自「包含各种测试,查找和算法等代码,如冒泡算法,树的遍历,链表,队列,堆栈等」· C++ 代码 · 共 44 行

CPP
44
字号
#include <iostream.h>
#include <stdlib.h>

typedef char VerT;
typedef char DataType;		
const int MaxVertices = 100;
const int MaxWeight = 10000;
const int MaxQueueSize = 100;

#include "AdjMWGraph.h"
#include "CreatAdjMWGraph.h"

void Printchar(char item)
{
	cout << item<<" ";
}

void main(void)
{
	AdjMWGraph g;
	char a[] = {'A','B','C','D','E'};
	RowColWeight rcw[] = {{0,1,10},{0,4,20},{1,3,30},{2,1,40},{3,2,50}};
	int n = 5, e = 5;

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

	cout << "顶点个数为:" << g.NumOfVertices() << endl;
	cout << "边的条数为:" << g.NumOfEdges() << endl;
	cout << "深度优先搜索序列为:";
	g.DepthFirstSearch(Printchar);
	cout << endl << "广度优先搜索序列为:";
	g.BroadFirstSearch(Printchar);

	g.DeleteVertex(3);
	g.DeleteEdge(0, 4);

	cout << endl << "顶点个数为:" << g.NumOfVertices();
	cout << endl << "边的条数为:" << g.NumOfEdges()<< endl;
	cout << "深度优先搜索序列为:";
	g.DepthFirstSearch(Printchar);
	cout << endl << "广度优先搜索序列为:";
	g.BroadFirstSearch(Printchar);
}

⌨️ 快捷键说明

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