目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以0结点为起点实现上述图的深度优先和广度优先遍历算法;
- 思路:
- 用堆栈实现深度优先遍历,用队列实现广度优先遍历。
- 最小生成树的算法实现
- 利用普里姆(Prim)算法或克鲁斯卡尔(Kruskal)算法求上图的最小生成树,算法实现代码必需有注释。
- 思路:
- Prim:从0点出发每次取能到达的最小权重边,走完即为一颗最小生成树。
- 最短路径的算法实现
- 利用狄克斯特拉(Dijkstra)算法求上图中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();
}
https://levitrav.store/# Levitra 10 mg best price
Purchase Cenforce Online: cenforce.pro – Cenforce 150 mg online
http://cenforce.pro/# buy cenforce
Buy Tadalafil 20mg Generic Cialis without a doctor prescription Cialis without a doctor prescription
buy cenforce: cheapest cenforce – order cenforce
buy Levitra over the counter: buy Levitra over the counter – Levitra price
buy Kamagra kamagra oral jelly Kamagra 100mg price
super kamagra: kamagra oral jelly – kamagra
https://kamagra.win/# sildenafil oral jelly 100mg kamagra
http://levitrav.store/# п»їLevitra price
https://cialist.pro/# Buy Tadalafil 20mg
cheap viagra Buy generic 100mg Viagra online buy Viagra online
Levitra online USA fast: levitrav.store – Levitra generic best price
buy cenforce Cenforce 150 mg online order cenforce
https://cialist.pro/# Buy Tadalafil 10mg
Levitra 10 mg best price: Buy generic Levitra online – Buy Vardenafil 20mg online
https://kamagra.win/# Kamagra tablets
http://cenforce.pro/# cenforce for sale
https://kamagra.win/# super kamagra
Levitra online USA fast Levitra generic price Levitra 20 mg for sale
cheapest cenforce: Buy Cenforce 100mg Online – Cenforce 100mg tablets for sale
Buy Tadalafil 10mg: Generic Cialis without a doctor prescription – cialis generic
http://kamagra.win/# buy Kamagra
best price for viagra 100mg: Cheapest place to buy Viagra – Cheap Sildenafil 100mg
buy cialis pill Generic Cialis without a doctor prescription Buy Tadalafil 5mg
Kamagra 100mg price: kamagra.win – Kamagra Oral Jelly
https://levitrav.store/# Levitra online USA fast
http://viagras.online/# Viagra tablet online
Vardenafil buy online Levitra 20 mg for sale Buy Vardenafil online
Cheap generic Viagra online: Buy Viagra online – Viagra generic over the counter
https://kamagra.win/# Kamagra Oral Jelly
generic sildenafil: viagra without prescription – Viagra generic over the counter
Vardenafil buy online Levitra generic price Levitra tablet price
http://viagras.online/# Buy Viagra online cheap
Levitra online pharmacy Vardenafil online prescription Levitra generic best price
buy cytotec over the counter: cytotec abortion pill – cytotec buy online usa
buy cytotec online: buy cytotec online – cytotec pills online
buy cytotec over the counter buy cytotec online п»їcytotec pills online
cost generic propecia without insurance buy generic propecia cost propecia without rx
http://ciprofloxacin.tech/# buy cipro online
where can i buy nolvadex: tamoxifen cancer – tamoxifen estrogen
cost cheap propecia online: propecia price – cost of propecia no prescription
lisinopril without rx can you order lisinopril online cheapest price for lisinopril india
https://lisinopril.network/# lisinopril 20 mg tabs
purchase cytotec cytotec buy online usa order cytotec online
http://ciprofloxacin.tech/# cipro for sale
http://finasteride.store/# buying propecia no prescription
Cytotec 200mcg price: buy cytotec over the counter – buy cytotec over the counter
http://cytotec.club/# cytotec pills buy online
prinivil 20mg tabs lisinopril 2 mg buy lisinopril 10 mg online