目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
Greetings! Very helpful advice within this article! It is the little changes which will make the greatest changes. Thanks for sharing!
Hello! I simply want to give you a big thumbs up for the great information you have got right here on this post. I am coming back to your blog for more soon.
best online pharmacies in mexico online mexican pharmacy medication from mexico pharmacy
https://cmqpharma.online/# medication from mexico pharmacy
mexico drug stores pharmacies
Насладитесь просмотра кинолент в превосходном качестве
онлайн – первоклассный онлайн кинозал.
Смотреть кино в сети верный выбор в 2024 году.
Кинокартины онлайн высоком качестве sizok.ru
buying from online mexican pharmacy cmq pharma mexican drugstore online
buying from online mexican pharmacy cmq pharma mexican pharmacy mexican online pharmacies prescription drugs
mexican online pharmacies prescription drugs mexican online pharmacy reputable mexican pharmacies online
Your insights have given me a new perspective.에볼루션 딜러 채용
mexican online pharmacies prescription drugs cmq pharma mexican border pharmacies shipping to usa
I will right away grab your rss feed to remain up to date on any succeeding articles you might write
mexico drug stores pharmacies mexican online pharmacy mexican mail order pharmacies
Your clarity is commendable.에볼루션 몰타
A friend of mine advised this site. And yes. it has some useful pieces of information and I enjoyed scaning it. Therefore i would love to drop you a quick note to express my cheers. Take care
oh cool, this information is really useful and definately is comment worthy! hehe. I’ll see if I can try to use some of this information for my own blog. Greetings from Nebraska
pharmacies in mexico that ship to usa cmq mexican pharmacy online best online pharmacies in mexico
Good – I should certainly pronounce, impressed with your site. I had no trouble navigating through all the tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, site theme . a tones way for your customer to communicate. Excellent task.
the morning fresh air is the best, i have asthma and i love to get some fresh air::
best online pharmacies in mexico mexico pharmacy pharmacies in mexico that ship to usa
Thank you, I’ve recently been hunting for info about this subject matter for ages and yours is the best I’ve located so far.
Can I just say that of a relief to uncover someone who truly knows what theyre talking about over the internet. You certainly have learned to bring a challenge to light and produce it essential. Lots more people must read this and can see this side of the story. I cant believe youre less well-liked since you certainly possess the gift.
mexican pharmacy cmq mexican pharmacy online buying prescription drugs in mexico
https://cmqpharma.online/# mexico drug stores pharmacies
buying prescription drugs in mexico online
Sweet blog! I found it while browsing on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Thank you
https://northern-doctors.org/# purple pharmacy mexico price list
buying prescription drugs in mexico online: mexican northern doctors – purple pharmacy mexico price list
purple pharmacy mexico price list: mexican pharmacy – mexico drug stores pharmacies
buying prescription drugs in mexico online: mexican pharmacy northern doctors – mexico pharmacy
mexican rx online mexican pharmacy mexico drug stores pharmacies
https://northern-doctors.org/# mexican rx online
Excellent ideas throughout this post, you just gained a brand new reader. Do you have any feedback on your most recent post though?
mexican online pharmacies prescription drugs: mexican pharmacy – mexican pharmacy
mexican border pharmacies shipping to usa: Mexico pharmacy that ship to usa – п»їbest mexican online pharmacies
hinduism is a good religion, my father is hindu and also my mother.
https://northern-doctors.org/# mexico pharmacies prescription drugs
Excellent blog here! Also your web site loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my website loaded up as quickly as yours lol
п»їbest mexican online pharmacies: mexican northern doctors – mexico pharmacy
After study a handful of the blog posts on your site now, and I really as if your way of blogging. I bookmarked it to my bookmark site list and you will be checking back soon. Pls look at my internet site in addition and let me know what you believe.
https://northern-doctors.org/# mexican rx online
mexico drug stores pharmacies: mexican pharmacy – medication from mexico pharmacy
mexican online pharmacies prescription drugs: mexican pharmacy northern doctors – mexican online pharmacies prescription drugs
https://northern-doctors.org/# mexican mail order pharmacies
Frustration is focused on what is currently happening and what has already happened.
mexican pharmacy: mexican pharmacy – purple pharmacy mexico price list
medicine in mexico pharmacies mexican pharmacy northern doctors reputable mexican pharmacies online
Откройте дверь к лучшей версии себя – кликните по линку на :~:text=%D0%A2%D1%80%D0%B8%20%D0%B4%D0%BE%D0%B3%D0%BC%D0%B0%D1%82%D0%B0-
I do not even know how I stopped up here, however I believed this post used to be great. I do not recognize who you are but certainly you’re going to a well-known blogger should you are not already Cheers!
mexico pharmacy: mexican northern doctors – reputable mexican pharmacies online
https://northern-doctors.org/# п»їbest mexican online pharmacies
I would be mendacity basically said i do not such as this article, in reality, I love this a great deal I needed to place upward a discuss right here. I must state maintain the good function, and that i will likely be arriving again for good since I already bookmarked the actual page.