關鍵路徑 C語言實現

2021-08-11 21:06:58 字數 2480 閱讀 7137

#include

#include

#define maxvertexnum 50

#define false 0

#define true 1

typedef int bool;

typedef int vertex;

typedef int weighttype;

struct vertexnode;//頂點結構

struct adjnode;//鄰接頂點結構

typedef struct adjnode *ptrtoadjvertexnode;//指向鄰接點的指標

typedef struct graphnode *ptrtographnode;//指向圖的指標

typedef ptrtographnode listgraph;

typedef struct edgenode *edge;

typedef struct vertexnode

adjlist[maxvertexnum];

struct adjnode

;struct graphnode

;/*將邊的資訊封裝,v1到v2權重為weight的邊*/

struct edgenode

;/*stack adt*/

typedef vertex elementtype;

typedef struct stacknode *stack;

struct stacknode

;int isemptystack(stack s);

int isfullstack(stack s);

stack creatstack(int capacity);

int push(elementtype x, stack s);

elementtype pop(stack s);

/*stack end*/

listgraph creatgraph(int vertexnum);

void insertedge(listgraph graph, edge e);

edge readedge(void);//輸入函式

int* getindegree(listgraph graph);

int topologicalorder(listgraph graph, stack t, int *vertexearlytime);//用於關鍵路徑的拓撲排序,傳入最早開工時間

int main()

criticalpath(graph);

return 0;

}listgraph creatgraph(int vertexnum)

return graph;

}void insertedge(listgraph graph, edge e)

edge readedge(void)

else

return e;

}int* getindegree(listgraph graph)

for (i=1; i<=graph->vertexnum; i++)

}return array;

}int topologicalorder(listgraph graph, stack t, int *vertexearlytime)

}while (!isemptystack(s))

if (vertexearlytime[j] + p->weight > vertexearlytime[k]) }}

printf("拓撲排序結果:\n");

if (isemptystack(t))

for (i = 0; i <= t->top; ++i)

printf("\n");

if (count < graph->vertexnum) else

}int criticalpath(listgraph graph)

if (!topologicalorder(graph, t ,vertexearlytime))

for (i=1; i<=graph->vertexnum; i++)

while (!isemptystack(t)) }}

printf("關鍵活動: \n");

for (j = 0; j<=graph->vertexnum; j++)

}return true;

}/*stack*/

int isemptystack(stack s)

int isfullstack(stack s)

stack creatstack(int capacity)

int push(elementtype x, stack s)

s->top++;

s->array[s->top] = x;

return true;

}elementtype pop(stack s)

return s->array[s->top--];

}

C語言實現「關鍵路徑」的求解

儘管是用c 編譯的,但程式中沒有應用什麼c 特性,應該算是c語言編寫吧。一 概述 工程上常常用乙個有向無環圖來代表乙個專案 如下圖 以節點表示某個事件,以邊表示活動,邊上的數字表示活動的持續時間。在工程分析上,常常需要找到一條 關鍵路徑 即此路徑直接決定專案的持續時間。二 演算法描述 為求出關鍵路徑...

關鍵路徑 C語言簡單實現

本文參考自 大話資料結構 對關鍵路徑的理解參考自 在乙個表示工程的帶權有向圖中,用頂點表示事件,用有向邊表示活動,用邊上的權值表示活動的持續時間,這種有向圖的邊表示活動的網,我們稱之為aoe網。我們把aoe網中沒有入邊的頂點稱為始點或源點,沒有出邊的頂點稱為終點或匯點。儘管aoe網和aov網都是用來...

最短路徑 C語言實現

dijkstra演算法具體步驟 1 初始時,s集合只包含源點 s u集合包含剩餘的點,源點v到自己的距離為0,到其他頂點的距離均為無窮大 表示不可達 以此更新dist陣列,除dist v 0之外,其餘全為無窮大 2 在dist陣列中,找到目前在u集合中且使得源點v到其距離最小的頂點k,將該頂點加入u...