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

📄 prg16_2.cpp

📁 数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码
💻 CPP
字号:
#ifdef _MSC_VER
// disable warning messages that identifier was truncated
// to 'number' characters in the debug information
#pragma warning(disable:4786)
#endif	// _MSC_VER

// File: prg16_2.cpp
// the program inputs a directed acyclic graph (DAG) from the file
// "dag.dat" and calls the graph algorithm acyclic() to verify that
// it has no cycles. adding an edge (E,A) creates a cycle in the
// graph. a call to acyclic() verifies the presence of the cycle

#include <iostream>
#include <fstream>
#include <string>

#include "d_graph.h"

using namespace std;

int main()
{
	graph<char> g;
	// the file that defines the graph
	ifstream graphIn;

	graphIn.open("dag.dat");

	// read the graph
	graphIn >> g;

	// determine if the graph is acyclic
	if (acyclic(g))
		cout << "Original graph is acyclic" << endl;
	else
		cout << "Original graph is not acyclic" << endl;

	// add edge (E,A) to create a cycle
	cout << "   Adding edge (E,A): ";
	g.insertEdge('E', 'A', 1);

	// retest the graph to see if it is acyclic
	if (acyclic(g))
		cout << "New graph is acyclic" << endl;
	else
		cout << "New graph is not acyclic" << endl;

	return 0;
}

/*
Run:

Original graph is acyclic
   Adding edge (E,A): New graph is not acyclic
*/

⌨️ 快捷键说明

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