图的操作与实现

/ 5,165评论 / 22185阅读 / 0点赞

目录

要求


源代码

若以下显示需要登录,请刷新页面或点击此处下载。


思考

若只求带权有向图G中从顶点i到顶点j的最短路径,如何修改Dijkstra 算法来实现这一功能?

void Dijkstra_way(int first_point)
{
	int* widget_list = new int[map_size];	//记录距离0的长度
	for (int i = map_size; i--;)
	{
		widget_list[i] = INF;
		adjList[i].weight = -1;
	}
	widget_list[first_point] = 0;
	adjList[first_point].weight = 0;
	for (int i = 1; i < map_size; ++i)
		for (int j = map_size; j--;)		//计算距离
			if (adjList[j].weight >= 0)
				for (node* node_p = adjList[j].next_p; node_p != NULL; node_p = node_p->next_p)
					if (widget_list[j] + node_p->weight < widget_list[node_p->data])
					{
						widget_list[node_p->data] = widget_list[j] + node_p->weight;
						adjList[node_p->data].weight = j;
					}
	cout << "<< Dijkstra 最短路径:" << endl;
	coolQueue<int> stack;
	for (int i = 0; i < map_size; ++i)
	{
		for (int j = i; j != first_point;)
		{
			stack.End_push(j);
			j = adjList[j].weight;
		}
		cout << "<< " << first_point;
		for (int pop_int = 0; stack.End_pop(pop_int);)
			cout << " -> " << pop_int;
		cout << endl;
		stack.clear();
	}
	adjList_reflush();
}
  1. Genuinely liked this entry. It provided plenty of useful information. Fantastic effort on composing this.

  2. Robertproke说道:

    https://paxlovid.ink/# п»їpaxlovid

  3. Frankdon说道:

    Gabapentin Pharm: neurontin tablets no script – Gabapentin Pharm

  4. Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  5. Edwardhem说道:

    Ivermectin Pharm Store ivermectin new zealand Ivermectin Pharm Store

  6. Robertproke说道:

    http://paxlovid.ink/# Paxlovid.ink

  7. By partnering with Prostate Cancer UK we hope to lift as much as we are able to to support what is a crucial charity, doing nice work.

  8. Martucci, Joe (December 17, 2020).

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注