目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
doxycycline brand name canada: doxycycline 50mg – doxycycline generic
There’s definately a lot to learn about this subject. I like all the points you made.
May I simply say what a relief to uncover someone that genuinely understands what they are talking about on the net. You actually realize how to bring an issue to light and make it important. More people ought to check this out and understand this side of the story. I was surprised you’re not more popular since you surely have the gift.
cost of generic clomid pill: cost of cheap clomid – buy generic clomid
http://paxloviddelivery.pro/# paxlovid for sale
Paxlovid over the counter: paxlovid generic – paxlovid covid
Hi there, I do believe your blog might be having web browser compatibility issues. Whenever I look at your web site in Safari, it looks fine however when opening in IE, it has some overlapping issues. I just wanted to give you a quick heads up! Besides that, great site!
Right here is the right blog for anybody who really wants to find out about this topic. You realize so much its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a fresh spin on a subject that’s been discussed for a long time. Excellent stuff, just wonderful.
http://clomiddelivery.pro/# where can i buy generic clomid
doxycycline cost in mexico: doxycycline 40 mg cost – doxycycline singapore
You made some decent points there. I checked on the web for additional information about the issue and found most individuals will go along with your views on this site.
http://paxloviddelivery.pro/# paxlovid covid
Aw, this was a very nice post. Taking a few minutes and actual effort to generate a great article… but what can I say… I put things off a lot and never manage to get nearly anything done.
http://clomiddelivery.pro/# can i get clomid without prescription
Aw, this was an incredibly good post. Finding the time and actual effort to make a really good article… but what can I say… I put things off a lot and don’t seem to get nearly anything done.
п»їpaxlovid: paxlovid for sale – paxlovid for sale
http://amoxildelivery.pro/# amoxicillin 775 mg
where buy generic clomid prices: where to buy clomid – where can i get cheap clomid no prescription
This site really has all of the info I wanted about this subject and didn’t know who to ask.
https://doxycyclinedelivery.pro/# doxycycline price comparison
Great info. Lucky me I recently found your blog by chance (stumbleupon). I have bookmarked it for later.
@Flum float ventolin tablet 2 mg: Ventolin inhaler price – buy ventolin inhaler
ventolin online uk
@Flum float prednisone 4mg tab: prednisone price canada – buy prednisone online paypal
@Flum float lasix for sale: furosemide online – furosemide 40mg
@Flum float mexico pharmacies prescription drugs: mexican mail order pharmacies – medicine in mexico pharmacies
https://paxloviddelivery.pro/# paxlovid for sale
doxycycline hyclate 100 mg cap: cheap doxycycline online uk – buy doxycycline online no prescription
I was very pleased to discover this great site. I need to to thank you for ones time for this wonderful read!! I definitely loved every bit of it and i also have you bookmarked to check out new things in your blog.
http://amoxildelivery.pro/# amoxicillin price without insurance
I was excited to find this website. I need to to thank you for ones time due to this wonderful read!! I definitely appreciated every little bit of it and i also have you saved as a favorite to check out new stuff on your site.
indian pharmacy: pharmacy website india – indian pharmacy paypal
https://canadapharmast.com/# canadianpharmacyworld
п»їbest mexican online pharmacies reputable mexican pharmacies online mexican pharmaceuticals online
canadian pharmacies compare: best canadian pharmacy to order from – pharmacy rx world canada
Hello! I just wish to give you a huge thumbs up for your great information you have got right here on this post. I am returning to your blog for more soon.
online canadian pharmacy review: canadian drugs – canada drugs online reviews
Your analysis is thorough and well-reasoned.Google Genius
pharmacies in mexico that ship to usa buying from online mexican pharmacy mexico drug stores pharmacies
http://indiapharmast.com/# online pharmacy india
canadian discount pharmacy: canadian pharmacy reviews – canadian pharmacy 365
safe reliable canadian pharmacy: pet meds without vet prescription canada – canada rx pharmacy world
best online pharmacy india: indian pharmacies safe – cheapest online pharmacy india
buying prescription drugs in mexico mexican mail order pharmacies reputable mexican pharmacies online
Great post! We will be linking to this particularly great post on our site. Keep up the good writing.
п»їbest mexican online pharmacies: best online pharmacies in mexico – mexico pharmacy
http://foruspharma.com/# mexico pharmacies prescription drugs
Excellent web site you have got here.. It’s difficult to find good quality writing like yours these days. I truly appreciate people like you! Take care!!
best mail order pharmacy canada: canadian pharmacy online ship to usa – canadian drug pharmacy
top 10 online pharmacy in india: world pharmacy india – world pharmacy india
prescription drugs canada buy online canadian pharmacy king canadian pharmacy 24h com safe
Oh my goodness! Awesome article dude! Thank you, However I am encountering problems with your RSS. I don’t know why I cannot join it. Is there anybody having the same RSS problems? Anyone who knows the answer will you kindly respond? Thanks!
Oh my goodness! Impressive article dude! Thanks, However I am encountering troubles with your RSS. I don’t know the reason why I can’t subscribe to it. Is there anybody getting identical RSS issues? Anyone that knows the answer can you kindly respond? Thanx.
Oh my goodness! Impressive article dude! Thanks, However I am going through problems with your RSS. I don’t know why I can’t join it. Is there anyone else getting similar RSS problems? Anybody who knows the solution will you kindly respond? Thanx!!
May I just say what a comfort to uncover someone that genuinely knows what they are talking about online. You actually know how to bring an issue to light and make it important. More and more people should check this out and understand this side of your story. I can’t believe you’re not more popular since you certainly have the gift.