目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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 ought to take part in a contest for one of the highest quality sites online. I most certainly will recommend this blog!
There is certainly a lot to know about this issue. I like all of the points you’ve made.
furosemide 40mg: furosemide online – lasix online
Very good blog post. I absolutely appreciate this site. Keep it up!
https://furosemide.win/# generic lasix
How can you “cash out” of the investment.
Zonomics by ING. This disambiguation page lists articles associated with the title Money printing.
Those who came home were profoundly affected by their war experience.
Banking acts lay down rules for banks which they have to observe when they are being established and when they are carrying on their business.
The first essential part of any plan is your emergency fund.
After I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get 4 emails with the exact same comment. There has to be an easy method you can remove me from that service? Kudos.
The 10 largest stock exchanges (New York and Mumbai have two exchanges each).
lipitor 40 mg: buy atorvastatin online – liptor
Rybczynski, Witold. “The Ranch House Anomaly: How America Fell in and out of Love with Them.” Slate.
Studies show an average 50-year-old gets as much light from a 100-watt bulb as a 20-year-old gets from a 50-watt bulb!
Wonderful post! We will be linking to this great content on our website. Keep up the great writing.
I would like to thank you for the efforts you have put in writing this blog. I’m hoping to check out the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has motivated me to get my own, personal site now 😉
https://lipitor.guru/# lipitor 5mg
You made some decent points there. I looked on the internet to learn more about the issue and found most individuals will go along with your views on this site.
lipitor prescription prices: buy lipitor 20mg – buy lipitor 40 mg
cytotec buy online usa http://lipitor.guru/# canada prescription price lipitor
lasix tablet
It’s hard to come by experienced people in this particular topic, however, you sound like you know what you’re talking about! Thanks
lasix 40 mg lasix side effects lasix dosage
tamoxifen buy: buy tamoxifen online – how to get nolvadex
An interesting discussion is definitely worth comment. I do believe that you ought to publish more about this subject, it may not be a taboo matter but typically folks don’t discuss such issues. To the next! Many thanks.
https://lisinopril.guru/# lisinopril 80
Hello there! This article couldn’t be written much better! Looking through this article reminds me of my previous roommate! He continually kept talking about this. I most certainly will send this information to him. Fairly certain he’ll have a great read. Thank you for sharing!
cytotec online: Misoprostol price in pharmacy – cytotec abortion pill
Cytotec 200mcg price cytotec best price purchase cytotec
Very nice article. I definitely love this website. Stick with it!
https://tamoxifen.bid/# how does tamoxifen work
how to prevent hair loss while on tamoxifen: nolvadex pct – nolvadex for sale
It’s hard to come by knowledgeable people in this particular topic, however, you sound like you know what you’re talking about! Thanks
tamoxifen bone density buy tamoxifen online tamoxifen hair loss
http://lipitor.guru/# lipitor generic price
lipitor brand name: Lipitor 10 mg price – lipitor 10 mg tablet
Spot on with this write-up, I actually feel this web site needs far more attention. I’ll probably be returning to read more, thanks for the info!
Oh my goodness! Impressive article dude! Many thanks, However I am going through troubles with your RSS. I don’t understand why I am unable to join it. Is there anybody else having the same RSS issues? Anybody who knows the answer will you kindly respond? Thanx!!
Hi there! I could have sworn I’ve visited this blog before but after browsing through some of the articles I realized it’s new to me. Anyways, I’m definitely happy I stumbled upon it and I’ll be book-marking it and checking back regularly.
Excellent blog post. I absolutely appreciate this website. Keep it up!
That is a really good tip especially to those fresh to the blogosphere. Brief but very precise info… Many thanks for sharing this one. A must read post!
Greetings! Very helpful advice within this post! It’s the little changes that produce the greatest changes. Thanks a lot for sharing!
Great info. Lucky me I found your site by chance (stumbleupon). I have saved as a favorite for later.
Adored this post. It’s extremely detailed and packed with helpful insights. Excellent effort!
https://www.youtube.com/watch?v=gCDNPENmMiw
Very good article! We are linking to this particularly great content on our website. Keep up the good writing.
mexican drugstore online: mexican rx online – mexican rx online
Very good post! We will be linking to this great post on our site. Keep up the great writing.
mexican border pharmacies shipping to usa: mexican pharmacy – mexican pharmaceuticals online
Hi there! This post couldn’t be written any better! Reading through this article reminds me of my previous roommate! He continually kept talking about this. I’ll send this article to him. Fairly certain he will have a very good read. I appreciate you for sharing!
I was very pleased to uncover this web site. I need to to thank you for your time due to this wonderful read!! I definitely savored every bit of it and I have you book marked to look at new things on your site.