目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
Hi, ich habe Ihre Webseite bei der Suche nach Fernbus Hamburg im Internet gefunden. Schauen Sie doch mal auf meiner Seite vorbei, ich habe dort viele Testberichte zu den aktuellen Windeleimern geschrieben.
i am very picky about baby toys, so i always choose the best ones.,
You made some decent points there. I looked on the web with the problem and discovered most people will go in addition to with all your site.
I liked up to you’ll receive carried out proper here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an nervousness over that you would like be handing over the following. in poor health no doubt come more formerly once more as exactly the similar nearly very often inside case you shield this increase.
This one is an inspiration personally to uncover out far more associated to this subject. I need to confess your knowledge prolonged my sentiments as well as I’m going to proper now take your feed to remain updated on each coming blog posts you would possibly presumably create. You are worthy of thanks for a job perfectly performed!
Good blog! I really love how it is easy on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a great day!
Hi there, I found your blog via Google while looking for a related topic, your site came up, it looks great. I’ve bookmarked it in my google bookmarks.
Only wanna input on few general things, The website layout is perfect, the written content is rattling superb .
My husband and i are already truly contented in which Raymond can deal with their inspections via the suggestions he obtained while using the web site. Now it is and also again complicated to simply be offering info that many some other individuals have recently been marketing. We realize we have the writer saying thanks to with this. The type of illustrations you have made, the easy internet site course-plotting, the particular romances you help to engender ?ê? it’s every thing remarkable, and it is making our child and us feel that this issue is pleasurable, and that’s amazingly necessary. Appreciate all!
Heya i am for the first time here. I found this board and I find It truly useful & it helped me out much. I hope to give something back and aid others like you aided me.
Hi there, I found your blog via Yahoo while searching for a related topic, your web site came up, it looks great. I’ve bookmarked it in my bookmarks.
In my opinion, when the ratio concerning daily life being a lever, values is its own “point”, while using proper rocker, it might become a amazing someone.
Hello, you used to write excellent, but the last several posts have been kinda boring?K I miss your tremendous writings. Past few posts are just a little bit out of track! come on!
Wholesale Cheap Handbags Are you ok basically repost this on my small site? Quite possibly to provide credit where it can be due. Have a very great day!
Dzięki za szczegółowy przewodnik po SEO. Bardzo pouczający!
levitra from canadian pharmacy
Świetne wskazówki dotyczące znalezienia wiarygodnych usług SEO. Dzięki!
Ten blog dostarczył mi dużo jasności na temat SEO. Dzięki!
Dzięki za szczegółowy przewodnik po tym, czego można oczekiwać podczas wdrażania SEO.
Pin up 306 casino: Pin-Up Casino – Pin Up Azerbaycan ?Onlayn Kazino
https://autolux-azerbaijan.com/# ?Onlayn Kazino
https://autolux-azerbaijan.com/# pin-up kazino
Pin Up Azerbaycan ?Onlayn Kazino: ?Onlayn Kazino – Pin Up Azerbaycan ?Onlayn Kazino
Bardzo pomocny post o SEO! Będę to udostępniać znajomym i rodzinie.
Pin Up Azerbaycan: Pin-up Giris – Pin up 306 casino
https://autolux-azerbaijan.com/# Pin-Up Casino
Pin Up Azerbaycan: pin-up kazino – Pin up 306 casino
pin-up kazino: pin-up 141 casino – Pin Up Azerbaycan ?Onlayn Kazino
Dzięki za szczegółowy przewodnik po tym, czego można oczekiwać podczas wdrażania SEO.
https://autolux-azerbaijan.com/# Pin up 306 casino
Ten blog wyjaśnia wiele zawiłości SEO. Dzięki!
https://autolux-azerbaijan.com/# pin-up kazino
Pin Up: pin-up kazino – Pin Up Kazino ?Onlayn
https://autolux-azerbaijan.com/# Pin Up
Pin Up Azerbaycan: Pin Up Azerbaycan – Pin up 306 casino
Dziękuję za podkreślenie znaczenia bezpieczeństwa w SEO.
https://autolux-azerbaijan.com/# pin-up kazino
Doceniam skupienie się na zagrożeniach SEO i potrzebie ich usunięcia.
Pin-Up Casino: Pin-Up Casino – ?Onlayn Kazino
https://autolux-azerbaijan.com/# pin-up 141 casino
Pin Up Azerbaycan: Pin-up Giris – Pin Up
https://autolux-azerbaijan.com/# Pin Up
Ten post był bardzo pomocny w zrozumieniu zawiłości SEO.
Pin Up Azerbaycan ?Onlayn Kazino: Pin-Up Casino – pin-up kazino
Dzięki za praktyczne porady dotyczące radzenia sobie z SEO.
Doceniam skupienie się na zagrożeniach SEO i potrzebie ich usunięcia.
Dzięki za podkreślenie znaczenia profesjonalnego podejścia do SEO.
I have to thank you for the efforts you have put in writing this website. I’m hoping to view the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has inspired me to get my own website now 😉
we always buy our dog supplies at least once a week from the local pet store. ;;
Doceniam nacisk na zdrowie i bezpieczeństwo w kontekście SEO.