【源代码】C++数据结构算法(十一)用邻接表实现图与关键路径

日常说明:首先博主也是菜鸟一枚,有错误欢迎大家指正。另外本博客所有的代码博主编写后均调试
通过。重要提醒!!!!博主使用的是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:
    
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值