目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
You’ve made some really good points there. I looked on the internet to find out more about the issue and found most people will go along with your views on this website.
I like looking through a post that will make people think. Also, thanks for allowing me to comment.
Heya just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same results.
Good web site you’ve got here.. It’s difficult to find high-quality writing like yours these days. I seriously appreciate individuals like you! Take care!!
You’re so awesome! I do not suppose I’ve read through anything like that before. So great to discover someone with original thoughts on this topic. Seriously.. many thanks for starting this up. This website is one thing that’s needed on the web, someone with a bit of originality.
It is really a great and helpful piece of info. I am glad that you just shared this helpful information with us. Please stay us informed like this. Thanks for sharing.
Im no expert, but I consider you just made the best point. You certainly know what youre talking about, and I can really get behind that. Thanks for being so upfront and so sincere.
I have been surfing online greater than three hours these days, yet I never discovered any fascinating article like yours. It’s lovely value sufficient for me. In my view, if all webmasters and bloggers made just right content material as you did, the internet will likely be a lot more helpful than ever before!
Have you already setup a fan page on Facebook ?~’-”;
Hey, have you ever previously considered to write regarding Nintendo Dsi handheld?
Thanks for making the trustworthy attempt to discuss this. I believe very strong approximately it and would like to learn more. If it’s OK, as you achieve extra extensive knowledge, may you mind including more articles very similar to this one with more information? It might be extraordinarily helpful and helpful for me and my friends.
It’s nearly impossible to find well-informed people about this subject, but you seem like you know what you’re talking about! Thanks
Hello! Do you know if they make any plugins to help with SEO?
I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
If you know of any please share. Thanks! I saw similar blog here: Best escape rooms
Hi my friend! I want to say that this post is amazing, great written and include almost all vital infos. I would like to see more posts like this .
Oh my goodness! an incredible post dude. Thank you Nonetheless I’m experiencing issue with ur rss . Do not know why Struggling to subscribe to it. Possibly there is anyone getting identical rss difficulty? Anybody who knows kindly respond. Thnkx
I believe there is a issue with your blog post making use of Opera web browser.
This would be the right weblog for anyone who wants to learn about this topic. You understand a whole lot its nearly hard to argue to you (not that When i would want…HaHa). You definitely put a fresh spin on the topic thats been revealed for many years. Wonderful stuff, just wonderful!
I’d like to visit your blog more often however recently it appears to be taking endlessly to come up. I go to from work, and our connection there is pretty good. Do you think the problem may very well be in your finish?
there are insurance agencies that are scam too so make sure that you deal with legit insurance agencies,.
Dead written subject matter, Really enjoyed reading through .
we should always be updated with current events because it is important for us to know the latest issues~
pharmacie en ligne pas cher: Pharmacies en ligne certifiees – acheter mГ©dicament en ligne sans ordonnance
trouver un mГ©dicament en pharmacie: pharmacie en ligne france livraison belgique – Pharmacie en ligne livraison Europe
pharmacie en ligne france livraison internationale: Levitra sans ordonnance 24h – trouver un mГ©dicament en pharmacie
Viagra sans ordonnance 24h Amazon: Quand une femme prend du Viagra homme – Viagra en france livraison rapide
SildГ©nafil 100 mg prix en pharmacie en France: Meilleur Viagra sans ordonnance 24h – Viagra prix pharmacie paris
Pharmacie en ligne livraison Europe: Acheter Cialis 20 mg pas cher – pharmacie en ligne france livraison belgique
Viagra pas cher paris: Viagra sans ordonnance 24h – Viagra homme sans prescription
pharmacie en ligne pas cher: kamagra livraison 24h – vente de mГ©dicament en ligne
pharmacies en ligne certifiГ©es: Levitra pharmacie en ligne – pharmacie en ligne france livraison belgique
pharmacie en ligne france pas cher: Levitra pharmacie en ligne – pharmacie en ligne avec ordonnance
pharmacie en ligne france livraison belgique: Pharmacie sans ordonnance – Pharmacie Internationale en ligne
Viagra gГ©nГ©rique pas cher livraison rapide: Viagra generique en pharmacie – Viagra vente libre allemagne
pharmacie en ligne pas cher: levitra generique sites surs – trouver un mГ©dicament en pharmacie
pharmacie en ligne: pharmacie en ligne pas cher – pharmacie en ligne france livraison internationale
Pharmacie en ligne livraison Europe: Medicaments en ligne livres en 24h – vente de mГ©dicament en ligne
Viagra femme ou trouver: Viagra generique en pharmacie – Quand une femme prend du Viagra homme
pharmacie en ligne france pas cher: Medicaments en ligne livres en 24h – Pharmacie sans ordonnance
http://levitraenligne.com/# pharmacie en ligne avec ordonnance
Viagra homme prix en pharmacie sans ordonnance: viagra sans ordonnance – Viagra pas cher livraison rapide france
vente de mГ©dicament en ligne: pharmacie en ligne livraison europe – vente de mГ©dicament en ligne
Pharmacie Internationale en ligne: kamagra en ligne – Pharmacie Internationale en ligne
Viagra vente libre allemagne: Viagra sans ordonnance 24h – Viagra pas cher livraison rapide france
I really appreciate the thoroughness of your research and the clarity of your writing. This was a very insightful post. Great job!slotcoin
Viagra vente libre pays: viagra en ligne – Viagra femme sans ordonnance 24h
Viagra vente libre pays: Acheter du Viagra sans ordonnance – Sildenafil teva 100 mg sans ordonnance
Pharmacie en ligne livraison Europe: kamagra livraison 24h – pharmacie en ligne avec ordonnance
vente de mГ©dicament en ligne: pharmacie en ligne sans ordonnance – trouver un mГ©dicament en pharmacie
pharmacie en ligne france pas cher: cialis generique – pharmacie en ligne livraison europe
trouver un mГ©dicament en pharmacie: Levitra pharmacie en ligne – pharmacie en ligne livraison europe