目录
要求
- 图的邻接表和邻接矩阵存储
- 建立下图的邻接表或邻接矩阵,并输出之;
- 思路:
- 通过遍历邻接矩阵,采用头插法即可构造邻接表。
- 图的各种遍历算法实现
- 以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();
}
buy cytotec pills: buy cytotec over the counter – Cytotec 200mcg price
http://lisinopril.network/# zestoretic 20 12.5 mg
http://cytotec.club/# cytotec buy online usa
tamoxifen therapy common side effects of tamoxifen tamoxifen reviews
tamoxifen and ovarian cancer: aromatase inhibitors tamoxifen – tamoxifen for sale
buy cytotec pills: cytotec abortion pill – buy cytotec in usa
cost of propecia prices cost of cheap propecia online get generic propecia prices
https://finasteride.store/# cost of propecia without prescription
https://ciprofloxacin.tech/# buy cipro online without prescription
https://lisinopril.network/# best price for lisinopril 20 mg
buy cytotec pills п»їcytotec pills online buy cytotec online fast delivery
cost of generic propecia: get propecia – generic propecia prices
tamoxifen therapy: lexapro and tamoxifen – tamoxifen for gynecomastia reviews
https://finasteride.store/# cost cheap propecia
https://finasteride.store/# order propecia tablets
buy cytotec in usa cytotec pills buy online buy cytotec online
http://cytotec.club/# buy cytotec
buy cipro online antibiotics cipro ciprofloxacin 500 mg tablet price
tamoxifen warning: tamoxifen alternatives – nolvadex 20mg
buy cytotec over the counter: buy cytotec over the counter – cytotec pills online
cheap propecia for sale get generic propecia without insurance cost generic propecia without rx
http://lisinopril.network/# lisinopril 5 mg brand name
zestoretic 20 25mg lisinopril brand name australia zestril 5 mg price
http://nolvadex.life/# aromatase inhibitor tamoxifen
http://lisinopril.network/# lisinopril 10 mg coupon
lisinopril 10 mg tablet cost: generic for prinivil – zestril lisinopril
cipro for sale: ciprofloxacin generic – cipro online no prescription in the usa
where can i buy cipro online ciprofloxacin generic ciprofloxacin 500mg buy online
http://finasteride.store/# order cheap propecia without insurance
lisinopril 25mg tablets lisinopril 1 mg lisinopril 3
https://cytotec.club/# cytotec abortion pill
get generic propecia without rx get generic propecia without rx buy propecia online
cost of lisinopril 10 mg: how much is lisinopril 5 mg – lisinopril pill
buy cheap propecia without insurance cheap propecia prices buying cheap propecia without a prescription
http://ciprofloxacin.tech/# cipro 500mg best prices
https://nolvadex.life/# tamoxifen lawsuit
https://lisinopril.network/# buy lisinopril without prescription
buy cytotec over the counter: buy misoprostol over the counter – cytotec pills online
buy misoprostol over the counter cytotec pills buy online cytotec abortion pill
lisinopril 30: lisinopril 40 coupon – cost of lisinopril
buy generic propecia pill buy cheap propecia without insurance buy propecia pills
http://cytotec.club/# cytotec pills buy online
https://cytotec.club/# purchase cytotec
tamoxifen for breast cancer prevention raloxifene vs tamoxifen buy nolvadex online
cost of cheap propecia: propecia without prescription – cheap propecia without insurance
tamoxifen for breast cancer prevention tamoxifen alternatives tamoxifen effectiveness
ciprofloxacin over the counter: ciprofloxacin 500mg buy online – buy generic ciprofloxacin
tamoxifen 20 mg tablet nolvadex vs clomid alternative to tamoxifen
https://finasteride.store/# generic propecia without a prescription
https://ciprofloxacin.tech/# antibiotics cipro