提交 87d1fa34 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 609d75ca
#include "CriticalPath.h"
Stack stack, TopoSortResult;
int Ve[MAX_VERTEX_NUM]; // 事件最早发生时间数组
int Vl[MAX_VERTEX_NUM]; // 事件最迟发生时间数组
int Ve[MAX_VERTEX_NUM]; // An array of the earliest events to occur
int Vl[MAX_VERTEX_NUM]; // Event latest occurrence time array
int main(int argc, char* argv[])
{
GraphList GraphList;
//
// 初始化图
// Initialize the figure
//
InitGraph(&GraphList);
......@@ -20,7 +20,7 @@ int main(int argc, char* argv[])
InitStack(&TopoSortResult);
//
// 关键路径
// The critical path
//
CriticalPath(&GraphList);
......@@ -32,7 +32,7 @@ int main(int argc, char* argv[])
//
// 销毁图
// Destruction of figure
//
DeleteGraph(&GraphList);
......@@ -41,10 +41,10 @@ int main(int argc, char* argv[])
/*
function:
求图中所有顶点的入度
Find the degree of entry of all vertices in the graph
parameter:
pGraphList -- 图指针
pGraphList -- Figure pointer
*/
void FindInDegree(GraphList *pGraphList)
......@@ -58,19 +58,19 @@ void FindInDegree(GraphList *pGraphList)
/*
function:
拓扑排序.将排序结果(顶点下标)压入栈 TopoSortResult 中
并计算事件最早发生时间的数组
Topological sort.Push the sorting result (vertex index) into the stack TopoSortResult
And computes the array of the earliest occurrence of the event
parameter:
pGraphList -- 图指针
pGraphList -- Figure pointer
returned value:
如果排序成功返回 1
如果排序失败返回 0
Returns 1 if the sort succeeds
Returns 1 if the sort fails
*/
int TopologicalSort(GraphList* pGraphList)
{
FindInDegree(pGraphList); // 求图中所有顶点的入度
FindInDegree(pGraphList); // Find the degree of entry of all vertices in the graph
//
// TODO: Add the code here
......@@ -81,25 +81,25 @@ int TopologicalSort(GraphList* pGraphList)
/*
function:
关键路径
The critical path
parameter:
pGraphList -- 图指针
pGraphList -- Figure pointer
returned value:
如果计算关键路径成功返回 1
如果计算关键路径失败返回 0
Returns 1 if critical path is calculated successfully
Returns 0 if critical path calculation fails
*/
int CriticalPath(GraphList* pGraphList)
{
EdgeNode* pEdgeNode; // 边(弧节点指针
EdgeNode* pEdgeNode; // Edge (arc) node pointer
int i, k; // The cursor
int ee, el; // 临时变量
int ee, el; // Temporary variable
TopologicalSort(pGraphList); // 拓扑排序
TopologicalSort(pGraphList); // Topological sort
//
// 初始化事件的最迟发生时间数组
// Initializes an array of the latest occurrence times of events
//
for(i = 0; i < pGraphList->length; i++)
Vl[i] = Ve[pGraphList->length - 1];
......@@ -113,19 +113,19 @@ int CriticalPath(GraphList* pGraphList)
/*
function:
使用给定的数据初始化图的邻接表
Initializes the graph's adjacency list with the given data
parameter:
pGraphList -- 图指针
pGraphList -- Figure pointer
*/
typedef struct Arc{
int Weight; // 权值.
int VexIndex; // 与该顶点邻接的顶点序列.
const char* Name; // 边(弧活动名称
int Weight; // The weight.
int VexIndex; // The sequence of vertices adjacent to this vertex.
const char* Name; // Side (arc) activity name
}Arc;
typedef struct VertexArrayEntry {
const char* Name; // 顶点名称.NULL 表示顶点序列结束.
Arc ArcArray[MAX_VERTEX_NUM]; // 边节点数组.
const char* Name; // Name of the vertices.NULL indicates the end of the vertex sequence.
Arc ArcArray[MAX_VERTEX_NUM]; // Edge array.
}VertexArrayEntry;
const VertexArrayEntry VertexArray[] =
{
......@@ -138,37 +138,37 @@ const VertexArrayEntry VertexArray[] =
{ "V7", { {2, 8, "a10"}} },
{ "V8", { {4, 8, "a11"}} },
{ "V9", { } },
{ NULL } // 结束标志
{ NULL } // End mark
};
/*
function:
初始化图
Initialize the figure
parameter:
pGraphList -- 图指针
pGraphList -- Figure pointer
*/
void InitGraph(GraphList* pGraphList)
{
int i, j; // The cursor
EdgeNode** pEdgeNodePtr; // 指向边(弧节点指针的指针
EdgeNode** pEdgeNodePtr; // Pointer to a pointer to an edge (arc) node pointer
//
// 重置图中的数据 length
// Reset the length of the data in the graph
//
pGraphList->length = 0;
//
// 使用给定的数据初始化图的邻接表
// Initializes the graph's adjacency list with the given data
//
for(i=0; i<MAX_VERTEX_NUM ;i++)
{
if(NULL == VertexArray[i].Name) // 顶点名称.NULL表示顶点序列结束.
if(NULL == VertexArray[i].Name) // Name of the vertices.NULL indicates the end of the vertex sequence.
break;
pGraphList->vexlist[i].name = VertexArray[i].Name;
pEdgeNodePtr = &pGraphList->vexlist[i].firstarc; // 使指针指向顶点数组的第一条边(初始化指针的位置
pEdgeNodePtr = &pGraphList->vexlist[i].firstarc; // Makes the pointer point to the first edge of the vertex array (where the pointer was initialized)
for(j=0; j<MAX_VERTEX_NUM; j++)
{
if(NULL == VertexArray[i].ArcArray[j].Name)
......@@ -191,10 +191,10 @@ void InitGraph(GraphList* pGraphList)
/*
function:
销毁图
Destruction of figure
parameter:
pGraphList -- 图指针
pGraphList -- Figure pointer
*/
void DeleteGraph(GraphList* pGraphList)
{
......@@ -223,9 +223,9 @@ parameter:
*/
void OutputResult(GraphList* pGraphList)
{
EdgeNode* pEdgeNode; // 边(弧节点指针
int i, k; // 下标
int ee, el; // 临时变量
EdgeNode* pEdgeNode; // Edge (arc) node pointer
int i, k; // The subscript
int ee, el; // Temporary variable
printf("VertexSeq:\t\t\t\t\t\t\t\t\t");
for(i = 0; i < pGraphList->length; i++)
......@@ -256,13 +256,13 @@ void OutputResult(GraphList* pGraphList)
for(pEdgeNode = pGraphList->vexlist[i].firstarc; pEdgeNode!=NULL; pEdgeNode = pEdgeNode->nextedge)
{
//
// 将边(弧节点指针指向的顶点下标保存到 k 中
// Save the vertex index that the edge (arc) node pointer points to in k
//
k = pEdgeNode->vertex;
//
// ee 保存 Ve[i] 的值,le 保存 Vl[k] 值并减去边节点指针对应的权值
// ee saves the value of Ve[i],le saves the value of Vl[k] and subtracts the weight corresponding to the edge node pointer
//
ee = Ve[i];
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论