提交 609d75ca 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 c330bb52
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
/* /*
功能: function:
初始化栈。 Initialize the stack.
参数: parameter:
pS -- 栈的指针 pS -- The stack pointer
*/ */
void InitStack(Stack* pS) void InitStack(Stack* pS)
{ {
...@@ -14,47 +14,47 @@ void InitStack(Stack* pS) ...@@ -14,47 +14,47 @@ void InitStack(Stack* pS)
} }
/* /*
功能: function:
将元素入栈。 Push elements on the stack.
参数: parameter:
pS -- 栈的指针 pS -- The stack pointer
Elem -- 入栈的元素 Elem -- Pushed elements
返回值: returned value:
如果插入成功返回入栈元素的值。 Returns the value of the pushed element if the insert succeeds.
如果插入失败返回 -1。 Returns -1 if insert fails.
*/ */
int Push(Stack* pS, int Elem) int Push(Stack* pS, int Elem)
{ {
// //
// 栈满,入栈失败。 // Stack full, push failed.
// //
if(MAX_STACK_LENGTH-1 < pS->top) if(MAX_STACK_LENGTH-1 < pS->top)
return -1; return -1;
pS->top++; pS->top++;
pS->buffer[pS->top] = Elem; // 将元素插入栈顶 pS->buffer[pS->top] = Elem; // Insert the element at the top of the stack
return Elem; return Elem;
} }
/* /*
功能: function:
将栈顶元素出栈 Pop the top element of the stack
参数: parameter:
pS -- 栈的指针 pS -- The stack pointer
返回值: returned value:
如果出栈成功返回出栈元素的值。 If the pop succeeds, the value of the pop element is returned.
如果出栈失败返回 -1。 Returns -1 if pop fails.
*/ */
int Pop(Stack* pS) int Pop(Stack* pS)
{ {
int Elem; int Elem;
// //
// 栈为空,出栈失败 // The stack is empty and the pop fails
// //
if(StackEmpty(pS)) if(StackEmpty(pS))
return -1; return -1;
...@@ -66,15 +66,15 @@ int Pop(Stack* pS) ...@@ -66,15 +66,15 @@ int Pop(Stack* pS)
} }
/* /*
功能: function:
判断栈是否为空。 Determines whether the stack is empty.
参数: parameter:
pQ -- 栈的指针 pQ -- The stack pointer
返回值: returned value:
如果栈空返回 1(真) Returns 1 if stack is empty.
如果栈非空返回 0(假) Returns 0 if the stack is not empty.
*/ */
int StackEmpty(Stack* pS) int StackEmpty(Stack* pS)
{ {
......
...@@ -14,7 +14,7 @@ int main(int argc, char* argv[]) ...@@ -14,7 +14,7 @@ int main(int argc, char* argv[])
InitGraph(&GraphList); InitGraph(&GraphList);
// //
// 调用 InitStack 函数初始化栈 // Call the InitStack function to initialize the stack
// //
InitStack(&stack); InitStack(&stack);
InitStack(&TopoSortResult); InitStack(&TopoSortResult);
...@@ -26,7 +26,7 @@ int main(int argc, char* argv[]) ...@@ -26,7 +26,7 @@ int main(int argc, char* argv[])
// //
// 输出结果 // output result
// //
OutputResult(&GraphList); OutputResult(&GraphList);
...@@ -40,10 +40,10 @@ int main(int argc, char* argv[]) ...@@ -40,10 +40,10 @@ int main(int argc, char* argv[])
} }
/* /*
功能: function:
求图中所有顶点的入度 求图中所有顶点的入度
参数: parameter:
pGraphList -- 图指针 pGraphList -- 图指针
*/ */
...@@ -51,20 +51,20 @@ void FindInDegree(GraphList *pGraphList) ...@@ -51,20 +51,20 @@ void FindInDegree(GraphList *pGraphList)
{ {
// //
// TODO: 在此添加代码 // TODO: Add the code here
// //
} }
/* /*
功能: function:
拓扑排序将排序结果(顶点下标)压入栈 TopoSortResult 中 拓扑排序.将排序结果(顶点下标)压入栈 TopoSortResult 中
并计算事件最早发生时间的数组 并计算事件最早发生时间的数组
参数: parameter:
pGraphList -- 图指针 pGraphList -- 图指针
返回值: returned value:
如果排序成功返回 1 如果排序成功返回 1
如果排序失败返回 0 如果排序失败返回 0
*/ */
...@@ -73,27 +73,27 @@ int TopologicalSort(GraphList* pGraphList) ...@@ -73,27 +73,27 @@ int TopologicalSort(GraphList* pGraphList)
FindInDegree(pGraphList); // 求图中所有顶点的入度 FindInDegree(pGraphList); // 求图中所有顶点的入度
// //
// TODO: 在此添加代码 // TODO: Add the code here
// //
return 0; return 0;
} }
/* /*
功能: function:
关键路径 关键路径
参数: parameter:
pGraphList -- 图指针 pGraphList -- 图指针
返回值: returned value:
如果计算关键路径成功返回 1 如果计算关键路径成功返回 1
如果计算关键路径失败返回 0 如果计算关键路径失败返回 0
*/ */
int CriticalPath(GraphList* pGraphList) int CriticalPath(GraphList* pGraphList)
{ {
EdgeNode* pEdgeNode; // 边(弧节点指针 EdgeNode* pEdgeNode; // 边(弧节点指针
int i, k; // 游标 int i, k; // The cursor
int ee, el; // 临时变量 int ee, el; // 临时变量
TopologicalSort(pGraphList); // 拓扑排序 TopologicalSort(pGraphList); // 拓扑排序
...@@ -105,27 +105,27 @@ int CriticalPath(GraphList* pGraphList) ...@@ -105,27 +105,27 @@ int CriticalPath(GraphList* pGraphList)
Vl[i] = Ve[pGraphList->length - 1]; Vl[i] = Ve[pGraphList->length - 1];
// //
// TODO: 在此添加代码 // TODO: Add the code here
// //
return 0; return 0;
} }
/* /*
功能: function:
使用给定的数据初始化图的邻接表 使用给定的数据初始化图的邻接表
参数: parameter:
pGraphList -- 图指针 pGraphList -- 图指针
*/ */
typedef struct Arc{ typedef struct Arc{
int Weight; // 权值 int Weight; // 权值.
int VexIndex; // 与该顶点邻接的顶点序列 int VexIndex; // 与该顶点邻接的顶点序列.
const char* Name; // 边(弧活动名称 const char* Name; // 边(弧活动名称
}Arc; }Arc;
typedef struct VertexArrayEntry { typedef struct VertexArrayEntry {
const char* Name; // 顶点名称。NULL 表示顶点序列结束。 const char* Name; // 顶点名称.NULL 表示顶点序列结束.
Arc ArcArray[MAX_VERTEX_NUM]; // 边节点数组 Arc ArcArray[MAX_VERTEX_NUM]; // 边节点数组.
}VertexArrayEntry; }VertexArrayEntry;
const VertexArrayEntry VertexArray[] = const VertexArrayEntry VertexArray[] =
{ {
...@@ -142,16 +142,16 @@ const VertexArrayEntry VertexArray[] = ...@@ -142,16 +142,16 @@ const VertexArrayEntry VertexArray[] =
}; };
/* /*
功能: function:
初始化图 初始化图
参数: parameter:
pGraphList -- 图指针 pGraphList -- 图指针
*/ */
void InitGraph(GraphList* pGraphList) void InitGraph(GraphList* pGraphList)
{ {
int i, j; // 游标 int i, j; // The cursor
EdgeNode** pEdgeNodePtr; // 指向边(弧节点指针的指针 EdgeNode** pEdgeNodePtr; // 指向边(弧节点指针的指针
// //
// 重置图中的数据 length // 重置图中的数据 length
...@@ -163,12 +163,12 @@ void InitGraph(GraphList* pGraphList) ...@@ -163,12 +163,12 @@ void InitGraph(GraphList* pGraphList)
// //
for(i=0; i<MAX_VERTEX_NUM ;i++) for(i=0; i<MAX_VERTEX_NUM ;i++)
{ {
if(NULL == VertexArray[i].Name) // 顶点名称。NULL表示顶点序列结束。 if(NULL == VertexArray[i].Name) // 顶点名称.NULL表示顶点序列结束.
break; break;
pGraphList->vexlist[i].name = VertexArray[i].Name; pGraphList->vexlist[i].name = VertexArray[i].Name;
pEdgeNodePtr = &pGraphList->vexlist[i].firstarc; // 使指针指向顶点数组的第一条边(初始化指针的位置 pEdgeNodePtr = &pGraphList->vexlist[i].firstarc; // 使指针指向顶点数组的第一条边(初始化指针的位置
for(j=0; j<MAX_VERTEX_NUM; j++) for(j=0; j<MAX_VERTEX_NUM; j++)
{ {
if(NULL == VertexArray[i].ArcArray[j].Name) if(NULL == VertexArray[i].ArcArray[j].Name)
...@@ -190,10 +190,10 @@ void InitGraph(GraphList* pGraphList) ...@@ -190,10 +190,10 @@ void InitGraph(GraphList* pGraphList)
} }
/* /*
功能: function:
销毁图 销毁图
参数: parameter:
pGraphList -- 图指针 pGraphList -- 图指针
*/ */
void DeleteGraph(GraphList* pGraphList) void DeleteGraph(GraphList* pGraphList)
...@@ -215,15 +215,15 @@ void DeleteGraph(GraphList* pGraphList) ...@@ -215,15 +215,15 @@ void DeleteGraph(GraphList* pGraphList)
} }
/* /*
功能: function:
输出结果 output result
参数: parameter:
nothing
*/ */
void OutputResult(GraphList* pGraphList) void OutputResult(GraphList* pGraphList)
{ {
EdgeNode* pEdgeNode; // 边(弧节点指针 EdgeNode* pEdgeNode; // 边(弧节点指针
int i, k; // 下标 int i, k; // 下标
int ee, el; // 临时变量 int ee, el; // 临时变量
...@@ -256,13 +256,13 @@ void OutputResult(GraphList* pGraphList) ...@@ -256,13 +256,13 @@ void OutputResult(GraphList* pGraphList)
for(pEdgeNode = pGraphList->vexlist[i].firstarc; pEdgeNode!=NULL; pEdgeNode = pEdgeNode->nextedge) for(pEdgeNode = pGraphList->vexlist[i].firstarc; pEdgeNode!=NULL; pEdgeNode = pEdgeNode->nextedge)
{ {
// //
// 将边(弧节点指针指向的顶点下标保存到 k 中 // 将边(弧节点指针指向的顶点下标保存到 k 中
// //
k = pEdgeNode->vertex; k = pEdgeNode->vertex;
// //
// ee 保存 Ve[i] 的值le 保存 Vl[k] 值并减去边节点指针对应的权值 // ee 保存 Ve[i] 的值,le 保存 Vl[k] 值并减去边节点指针对应的权值
// //
ee = Ve[i]; ee = Ve[i];
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论