目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
п»їbest mexican online pharmacies: medicine in mexico pharmacies – buying from online mexican pharmacy
Online medicine home delivery: india pharmacy – top online pharmacy india
buying from online mexican pharmacy mexican pharmaceuticals online mexico drug stores pharmacies
http://pharmbig24.com/# lasix pharmacy
Nice post. I learn something totally new and challenging on websites I stumbleupon every day. It’s always interesting to read content from other authors and use a little something from their web sites.
Профессиональный сервисный центр по ремонту видео техники а именно видеокамер.
Мы предлагаем: ремонт камер
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
target pharmacy zocor adipex diet pills online pharmacy rx pharmacy near me
legitimate online pharmacy no prescription: kamagra pharmacy online – list of online pharmacies
indian pharmacy: top 10 pharmacies in india – indian pharmacy paypal
Если вы искали где отремонтировать сломаную технику, обратите внимание – сервис центр в казани
http://mexicopharmacy.cheap/# mexican rx online
indian pharmacies safe buy prescription drugs from india top 10 online pharmacy in india
trazodone pharmacy: gabapentin pharmacy prices – Diamox
mexico pharmacies prescription drugs: mexican online pharmacies prescription drugs – buying prescription drugs in mexico
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем:ремонт крупногабаритной техники в новосибирске
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
п»їlegitimate online pharmacies india pharmacy website india world pharmacy india
https://pharmbig24.online/# your pharmacy ibuprofen
mexican border pharmacies shipping to usa: п»їbest mexican online pharmacies – medication from mexico pharmacy
Профессиональный сервисный центр по ремонту планшетов в Москве.
Мы предлагаем: сколько стоит починка планшета
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
mexican drugstore online: mexican online pharmacies prescription drugs – reputable mexican pharmacies online
п»їbest mexican online pharmacies pharmacies in mexico that ship to usa mexican mail order pharmacies
Если вы искали где отремонтировать сломаную технику, обратите внимание – техпрофи
medicine in mexico pharmacies: medicine in mexico pharmacies – mexico drug stores pharmacies
Excellent post. I definitely love this website. Keep it up!
http://pharmbig24.com/# cipro online pharmacy
reputable indian online pharmacy: reputable indian pharmacies – п»їlegitimate online pharmacies india
mexican pharmaceuticals online medicine in mexico pharmacies mexico drug stores pharmacies
There’s definately a great deal to find out about this topic. I like all of the points you made.
Good blog you’ve got here.. It’s difficult to find excellent writing like yours nowadays. I really appreciate people like you! Take care!!
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 web site.
Great post. I will be facing some of these issues as well..
Good day! I could have sworn I’ve been to your blog before but after looking at some of the posts I realized it’s new to me. Regardless, I’m definitely pleased I came across it and I’ll be book-marking it and checking back regularly!
Can I just say what a relief to find an individual who really understands what they are talking about on the web. You certainly realize how to bring an issue to light and make it important. More people need to look at this and understand this side of the story. I can’t believe you aren’t more popular since you most certainly have the gift.
Профессиональный сервисный центр по ремонту фото техники от зеркальных до цифровых фотоаппаратов.
Мы предлагаем: ремонт цифровых фотоаппаратов
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
I truly love your site.. Excellent colors & theme. Did you build this web site yourself? Please reply back as I’m trying to create my own personal website and would like to find out where you got this from or what the theme is called. Thanks.
bangkok pharmacy kamagra: ed pharmacy cialis – turkey pharmacy online
This website was… how do you say it? Relevant!! Finally I have found something which helped me. Kudos.
Your style is very unique compared to other folks I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just bookmark this site.
I’ve bookmarked this for future reference.오피
Pretty! This has been a really wonderful article. Thanks for providing this information.
Zerit: usa online pharmacy – permethrin uk pharmacy
This post is fantastic! Filled with valuable details and extremely articulate. Many thanks for providing this.
I want to to thank you for this very good read!! I certainly loved every bit of it. I have you saved as a favorite to look at new things you post…
bookmarked!!, I like your web site!
Really enjoyed reading this entry. It’s extremely well-written and packed with useful information. Many thanks for sharing this.
fry’s food store pharmacy: specialty rx pharmacy – online pharmacy paroxetine
Good article. I will be facing some of these issues as well..
ed meds: rx pharmacy richland wa – ramesh rx pharmacy
periactin online pharmacy no prescription: target pharmacy fluoxetine – online us pharmacy
Если вы искали где отремонтировать сломаную технику, обратите внимание – сервисный центр в челябинске