日常说明:首先博主也是菜鸟一枚,有错误欢迎大家指正。另外本博客所有的代码博主编写后均调试
通过。重要提醒!!!!博主使用的是VS2017,如果有低版本的小伙伴
最好新建空项目将此代码复制上去。
更多算法请关注我的算法专栏https://blog.youkuaiyun.com/column/details/20417.html
学过的同学都知道,求得关键路径,要先看拓扑排序能否进行下去,如果一个工程连进行下去都满足不了,更不会有竣工了,关键路径也无从谈起,因此关键路径的算法是建立在拓扑排序的基础上的,可以参照《算法十》中的具体代码。但有一点小小的修改就是在拓扑排序中比较好实现最早开始时间的求解,所以就添加了两行代码。
运行截图:

MainPath.h
#pragma once
/**********************************
* algorithms.h : 拓扑排序与关键路径 *
* author : shilei *
* created : 2018.4.26 *
***********************************/
#define Max 100
#include <iostream>
#include <cstdlib>
#include<stack>
#include<stdexcept>
typedef int indegree[Max];
using namespace std;
class ArcNode
{
public:
int Vnum;
int weight;
ArcNode *arc_next;
ArcNode()
{
this->arc_next = NULL;
}
ArcNode(int Vnum, ArcNode*arc_next = NULL)
{
this->arc_next = arc_next;
this->Vnum = Vnum;
this->weight = weight;
}
};
typedef struct VNode
{
char data;
ArcNode *firstedge;
}VNode, AdjList[Max];
class ALGraph
{
public:
ALGraph(indegree indeg);
int TopologicalSort(ALGraph &graph, indegree indegree);
void MainPath(ALGraph&graph,indegree indegree);
//private:

最低0.47元/天 解锁文章
8756

被折叠的 条评论
为什么被折叠?



