目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
With the help of this method, the technical analysis helps investors to come to have a right investment decision.
mexican pharmaceuticals online: mexico pharmacy win – mexican pharmaceuticals online
Kit cars usually lack modern safety conveniences like airbags, crumple zones and backup cameras, so they should be driven with caution on the street.
You’re so cool! I do not think I’ve read through anything like this before. So wonderful to find another person with a few genuine thoughts on this subject matter. Seriously.. thanks for starting this up. This web site is something that’s needed on the web, someone with a little originality.
A new form of investing that seems to have caught the attention of investors is Venture Capital.
Let us say you believe the Barclays share price will increase in the near future, so you obviously want to buy the Barclays market.
https://edpillpharmacy.store/# cheap ed pills online
I really like it when people come together and share opinions. Great website, continue the good work!
mexico pharmacies prescription drugs: mexican mail order pharmacies – medication from mexico pharmacy
Howdy! This post couldn’t be written any better! Reading through this article reminds me of my previous roommate! He constantly kept talking about this. I’ll send this article to him. Fairly certain he’s going to have a very good read. Thanks for sharing!
Having read this I thought it was very informative. I appreciate you finding the time and effort to put this article together. I once again find myself spending way too much time both reading and commenting. But so what, it was still worth it!
cheapest ed pills: online ed treatments – ed pills for sale
https://mexicopharmacy.win/# buying prescription drugs in mexico
Nice post. I learn something totally new and challenging on sites I stumbleupon everyday. It will always be exciting to read content from other writers and use a little something from their sites.
This article is wonderful. I picked up tons from perusing it. The information is highly enlightening and arranged.
Hello there! I could have sworn I’ve visited this web site before but after browsing through many of the articles I realized it’s new to me. Regardless, I’m definitely happy I discovered it and I’ll be book-marking it and checking back often.
Online medicine home delivery: Indian pharmacy international shipping – top 10 pharmacies in india
https://indiapharmacy.shop/# india pharmacy
cheapest ed medication
I must thank you for the efforts you have put in writing this site. I really hope to see the same high-grade content from you later on as well. In truth, your creative writing abilities has inspired me to get my very own site now 😉
This post is extremely educational. I truly enjoyed reading it. The details is highly arranged and simple to understand.
https://indiapharmacy.shop/# top 10 online pharmacy in india
http://edpillpharmacy.store/# ed treatment online
erectile dysfunction online
mexican mail order pharmacies: mexico pharmacies prescription drugs – best online pharmacies in mexico
Aw, this was a really nice post. Spending some time and actual effort to create a superb article… but what can I say… I procrastinate a whole lot and never seem to get nearly anything done.
http://mexicopharmacy.win/# purple pharmacy mexico price list
indian pharmacy paypal: Online India pharmacy – top 10 online pharmacy in india
This site definitely has all the info I needed concerning this subject and didn’t know who to ask.
http://tadalafil.auction/# cialis no prescription canada
Good post. I learn something totally new and challenging on sites I stumbleupon on a daily basis. It’s always useful to read articles from other writers and use something from their web sites.
buy viagra generic: Buy Viagra online in USA – viagra professional
Your style is very unique compared to other folks I’ve read stuff from. I appreciate you for posting when you’ve got the opportunity, Guess I’ll just bookmark this web site.
Oh my goodness! Awesome article dude! Thanks, However I am going through difficulties with your RSS. I don’t understand why I cannot subscribe to it. Is there anybody else having similar RSS issues? Anybody who knows the solution can you kindly respond? Thanks!!
viagra samples: Buy Viagra online in USA – viagra canada
You ought to be a part of a contest for one of the most useful blogs on the net. I will recommend this site!
https://tadalafil.auction/# how can i get cialis in australia
This is a very good tip particularly to those new to the blogosphere. Simple but very precise info… Thanks for sharing this one. A must read post.
over the counter viagra cialis: Buy Cialis online – cialis au
Great post. I am going through a few of these issues as well..
It’s hard to come by well-informed people in this particular subject, however, you sound like you know what you’re talking about! Thanks
Can’t wait to read more of your articles in the future. thumbs up!.
http://tadalafil.auction/# online pharmacy cialis comparison
viagra online: Viagra without a doctor prescription – viagra price
Farmacia online miglior prezzo: avanafil senza ricetta – comprare farmaci online all’estero
A fascinating discussion is worth comment. I do believe that you ought to publish more about this topic, it may not be a taboo matter but typically people don’t discuss such issues. To the next! All the best!
https://avanafil.pro/# farmacie online affidabili
acquistare farmaci senza ricetta: Tadalafil generico migliore – Farmacia online piГ№ conveniente
This website was… how do you say it? Relevant!! Finally I have found something that helped me. Appreciate it!
You’re so interesting! I do not believe I’ve truly read through a single thing like this before. So good to find somebody with genuine thoughts on this subject. Seriously.. thank you for starting this up. This site is something that is required on the web, someone with a bit of originality.
acquistare farmaci senza ricetta: farmacia online migliore – comprare farmaci online con ricetta
I really like reading through a post that can make people think. Also, thanks for permitting me to comment.