prg16_3.cpp

来自「这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言」· C++ 代码 · 共 55 行

CPP
55
字号
#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_3.cpp
// the program inputs a directed acyclic graph that describes course
// prerequisites in a religious studies departmen. it performs
// a topological sort and outputs the result as a possible schedule
// of courses

#include <iostream>
#include <string>
#include <list>

#include "d_graph.h"
#include "d_util.h"

using namespace std;

int main()
{
	// graph specifying the courses and prerequisite edges
	graph<string> g;

	// a list holding the topological order of courses
	list<string> tlist;

	// input file holding the vertex strings and edges
	ifstream graphIn;

	// open the file and input the graph
	graphIn.open("courses.dat");
	graphIn >> g;

	// execute a topological sort; store results in list
	topologicalSort(g,tlist);

	// output the list of possible courses 
	cout << "Possible schedule of courses"
		  << endl << "    ";
	writeContainer(tlist.begin(), tlist.end());
	cout << endl;

	return 0;
}

/*
Run:

Possible schedule of courses
    R51  R53  R173  R151  R37  R137  R63  R263
*/

⌨️ 快捷键说明

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