提交 8efe800c 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 51155969
...@@ -4,11 +4,11 @@ Stack stack; ...@@ -4,11 +4,11 @@ Stack stack;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
GraphList Graphlist; // 用于拓扑排序的图 GraphList Graphlist; // A graph used for topological sorting
int i; int i;
// //
// 初始化图 // Initialize the figure
// //
InitGraph(&Graphlist); InitGraph(&Graphlist);
...@@ -18,14 +18,14 @@ int main(int argc, char* argv[]) ...@@ -18,14 +18,14 @@ int main(int argc, char* argv[])
InitStack(&stack); InitStack(&stack);
// //
// 拓扑排序 // Topological sort
// //
TopoSort(&Graphlist); TopoSort(&Graphlist);
OutputSortResult(&Graphlist); OutputSortResult(&Graphlist);
// //
// 销毁图 // Destruction of figure
// //
DeleteGraph(&Graphlist); DeleteGraph(&Graphlist);
...@@ -34,10 +34,10 @@ int main(int argc, char* argv[]) ...@@ -34,10 +34,10 @@ int main(int argc, char* argv[])
/* /*
function: function:
求图中所有顶点的入度 Find the degree of entry of all vertices in the graph
parameter: parameter:
pGraphList -- 图指针 pGraphList -- Figure pointer
*/ */
void FindInDegree(GraphList *pGraphList) void FindInDegree(GraphList *pGraphList)
...@@ -51,20 +51,20 @@ void FindInDegree(GraphList *pGraphList) ...@@ -51,20 +51,20 @@ void FindInDegree(GraphList *pGraphList)
/* /*
function: function:
拓扑排序 Topological sort
parameter: parameter:
pGraphList -- 图指针 pGraphList -- Figure pointer
returned value: returned value:
如果排序成功返回 1 Returns 1 if the sort succeeds
如果排序失败返回 0 Returns 1 if the sort fails
*/ */
int TopoSortResult[MAX_VERTEX_NUM]; // 存储排序结果(下标)的数组 int TopoSortResult[MAX_VERTEX_NUM]; // An array that stores sorted results (subscripts)
int ResultLength = 0; // The length of the array that stores the sorted result (subscript) int ResultLength = 0; // The length of the array that stores the sorted result (subscript)
int TopoSort(GraphList *pGraphList) int TopoSort(GraphList *pGraphList)
{ {
EdgeNode* pEdgeNode; // 边(弧节点指针 EdgeNode* pEdgeNode; // Edge (arc) node pointer
int i, k; // The cursor int i, k; // The cursor
// //
...@@ -77,14 +77,14 @@ int TopoSort(GraphList *pGraphList) ...@@ -77,14 +77,14 @@ int TopoSort(GraphList *pGraphList)
/* /*
function: function:
使用给定的数据初始化图的邻接表 Initializes the graph's adjacency list with the given data
parameter: parameter:
pGraphList -- 图指针 pGraphList -- Figure pointer
*/ */
typedef struct VertexArrayEntry { typedef struct VertexArrayEntry {
const char* name; // 顶点名称.NULL 表示顶点序列结束. const char* name; // Name of the vertices.NULL indicates the end of the vertex sequence.
int VexIndex[MAX_VERTEX_NUM]; // 与该顶点邻接的顶点序列.-1 表示序列结束. int VexIndex[MAX_VERTEX_NUM]; // The sequence of vertices adjacent to this vertex.-1 indicates the end of the sequence.
}VertexArrayEntry; }VertexArrayEntry;
const VertexArrayEntry VertexArray[] = { const VertexArrayEntry VertexArray[] = {
{ "C1", {2, 1, 3, 11, -1}}, { "C1", {2, 1, 3, 11, -1}},
...@@ -99,30 +99,30 @@ const VertexArrayEntry VertexArray[] = { ...@@ -99,30 +99,30 @@ const VertexArrayEntry VertexArray[] = {
{ "C10",{11, -1} }, { "C10",{11, -1} },
{ "C11",{5, -1} }, { "C11",{5, -1} },
{ "C12",{-1} }, { "C12",{-1} },
{ NULL } // 结束标志 { NULL } // End mark
}; };
void InitGraph(GraphList* pGraphList) void InitGraph(GraphList* pGraphList)
{ {
int i, j; // The cursor 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; pGraphList->length = 0;
// //
// 使用给定的数据初始化图的邻接表 // Initializes the graph's adjacency list with the given data
// //
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) // Name of the vertices.NULL indicates the end of the vertex sequence.
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; // Pointer to vertex array (where pointer is initialized)
for(j=0; j<MAX_VERTEX_NUM; j++) for(j=0; j<MAX_VERTEX_NUM; j++)
{ {
if(-1 == VertexArray[i].VexIndex[j]) if(-1 == VertexArray[i].VexIndex[j])
...@@ -142,10 +142,10 @@ void InitGraph(GraphList* pGraphList) ...@@ -142,10 +142,10 @@ void InitGraph(GraphList* pGraphList)
/* /*
function: function:
销毁图 Destruction of figure
parameter: parameter:
pGraphList -- 图指针 pGraphList -- Figure pointer
*/ */
void DeleteGraph(GraphList* pGraphList) void DeleteGraph(GraphList* pGraphList)
{ {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论