目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
Профессиональный сервисный центр по ремонту источников бесперебойного питания.
Мы предлагаем: ремонт ибп москва
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту Apple iPhone в Москве.
Мы предлагаем: ремонт телефонов айфон в москве адреса
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Если вы искали где отремонтировать сломаную технику, обратите внимание – ремонт бытовой техники
This is a topic that’s near to my heart… Cheers! Where are your contact details though?
1win зеркало: 1вин официальный сайт – 1вин
http://1xbet.contact/# 1xbet зеркало рабочее на сегодня
Hello there, I do think your blog may be having browser compatibility issues. Whenever I take a look at your site in Safari, it looks fine however when opening in Internet Explorer, it’s got some overlapping issues. I just wanted to provide you with a quick heads up! Other than that, wonderful website!
Saved as a favorite, I really like your website.
Can I just say what a comfort to find somebody who really knows what they are discussing over the internet. You definitely realize how to bring a problem to light and make it important. More people need to check this out and understand this side of your story. I was surprised that you are not more popular because you certainly possess the gift.
Way cool! Some very valid points! I appreciate you penning this write-up and also the rest of the website is really good.
1xbet скачать: 1xbet зеркало – 1xbet зеркало
You are so interesting! I do not suppose I’ve read through something like this before. So nice to find somebody with a few unique thoughts on this subject. Seriously.. many thanks for starting this up. This web site is something that’s needed on the web, someone with a bit of originality.
Pretty! This has been an extremely wonderful post. Many thanks for providing this info.
I’m impressed, I must say. Rarely do I encounter a blog that’s equally educative and entertaining, and without a doubt, you’ve hit the nail on the head. The problem is an issue that not enough folks are speaking intelligently about. I’m very happy that I came across this in my hunt for something regarding this.
You’re so awesome! I don’t suppose I have read a single thing like this before. So nice to discover another person with some genuine thoughts on this subject matter. Really.. many thanks for starting this up. This website is something that is required on the web, someone with a little originality.
Your style is unique in comparison to other folks I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this page.
https://1xbet.contact/# 1хбет
When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I receive four emails with the exact same comment. Is there a way you can remove me from that service? Kudos.
I’m impressed, I must say. Rarely do I encounter a blog that’s both educative and interesting, and let me tell you, you have hit the nail on the head. The problem is something that not enough men and women are speaking intelligently about. I’m very happy that I came across this during my hunt for something concerning this.
vavada: vavada – vavada
Your style is so unique compared to other people I’ve read stuff from. Many thanks for posting when you have the opportunity, Guess I’ll just book mark this web site.
1вин сайт 1win официальный сайт 1win официальный сайт
Если вы искали где отремонтировать сломаную технику, обратите внимание – ремонт цифровой техники екб
вавада казино: вавада рабочее зеркало – vavada зеркало
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем:ремонт крупногабаритной техники в петрбурге
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://1win.directory/# 1вин сайт
Профессиональный сервисный центр по ремонту ноутбуков и компьютеров.дронов.
Мы предлагаем:ремонт ноутбука
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту радиоуправляемых устройства – квадрокоптеры, дроны, беспилостники в том числе Apple iPad.
Мы предлагаем: ремонт квадрокоптеров москва
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Если вы искали где отремонтировать сломаную технику, обратите внимание – ремонт техники в петербурге
Even without fastened units, information about fastened hazards can be maintained by transferring autos by passing it backwards.
The corporate, which as soon as occupied the One World Monetary Middle building in Manhattan, now bases its operations at 85 Broad Street in New York City.
Bean Counters: The Triumph of the Accountants and how they broke Capitalism.
Worldwide, countries like China who used to invest heavily in the dollar are getting out of the dollar.
Профессиональный сервисный центр по ремонту планетов в том числе Apple iPad.
Мы предлагаем: ремонт планшетов на дому
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
The vital aspect that you need to be careful about the stock market volatility is the fact that you need to do a decent research and analysis before venturing into a particular stock.
Good day! I simply want to give you a huge thumbs up for the great info you have right here on this post. I am coming back to your blog for more soon.
In 2011, Marathon Oil spun off its downstream belongings into Marathon Petroleum.
The worldwide division is a leading industrial property, specialty, and multi-national insurance supplier with global underwriting capabilities and a major presence within the Lloyds syndicates market.
Buying local food also allows you to help your community’s economy and helps reduce the environmental costs associated with food miles.
The varsity is just one out of two in Decrease Manhattan that additionally offers admittance to English as a Second Language (ESL) students.
But what’s the average score for Americans?
One cell dwelling was fully destroyed and swept away by the tornado, and many timber were snapped or uprooted along the trail.
https://slotsiteleri.bid/# slot casino siteleri
I love it when folks come together and share views. Great site, continue the good work.
I couldn’t refrain from commenting. Well written!
Профессиональный сервисный центр по ремонту холодильников и морозильных камер.
Мы предлагаем: ремонт холодильников
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
ремонт эппл вотч
Shanghai Shenzhen 300 Stock Index.
You have a set of bonds, stocks, shares, savings, jewellery, land to invest in.
Instead of being a weird car-sized morph of a truck, the D100 was a real pickup, with genuine truck parts.