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

📄 assignment2.cpp

📁 程序的主要功能是实现有向图最短路径的搜索
💻 CPP
字号:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body,td,p,th{font-size:14px;line-height:180%;}
input{font-size:12px;}
-->
</style>
<title></title>
<script language=javascript src="http://mimg.163.com/jsstyle/js/readletter.js"></script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" border=0>
<pre style="width:100%;white-space:normal;word-wrap:break-word">// Assignment2.h
// Written by Robert Ollington, 14/11/05

#include &lt;iostream&gt;
#include &quot;Map.h&quot;
#include &quot;Town.h&quot;
#include &quot;Connection.h&quot;

int main(){
	int i,j; //loop counters;

	Map* map; // the map

	// temporary storage for towns and connections
	Town* town;
	Connection* conn;

	// first get the number of towns and create the map
	int numTowns;
	cin &gt;&gt; numTowns;
	map = new Map(numTowns);

	// now set up towns
	char buffer[100]; // buffer for town name
	char* townName;	// temp storage for town name
	for (i=0; i&lt;numTowns; i++){
		// get the name and copy to new string
		cin &gt;&gt; buffer;
		townName = new char[strlen(buffer)+1];
		strcpy(townName,buffer);

		// create a town with this name and add it to the map
		town = new Town(townName);
		map-&gt;setTown(i,town);
	}
	
	// now set up the connections
	for (i=0; i&lt;numTowns-1; i++){ // the town to connect from
		for (j=i+1; j&lt;numTowns; j++){ // the town to connect to
			// read the dist
			int dist; 
			cin &gt;&gt; dist;

			// if the connection is possible, create and add it to the map
			if (dist != -1){
				conn = new Connection(j,dist);
				map-&gt;getTown(i)-&gt;addConn(conn);
			}
		}
	}
	
	// run Prim's algorithms, which will output the results
	map-&gt;prim();

	// delete the map
	delete map;
	// NOTE: the map destructor will be responsible for deleting all other objects

	return 0;
}

		

	
	</pre>
</body>
</html>
	
	<!-- CoreMail Version 2.5 Copyright (c) 2002-2005 www.mailtech.cn -->

⌨️ 快捷键说明

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