Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab018
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab018
提交
c43bc431
提交
c43bc431
8月 15, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
7d46d513
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
47 行增加
和
42 行删除
+47
-42
CriticalPath.h
CriticalPath.h
+8
-11
Stack.c
Stack.c
+6
-2
Stack.h
Stack.h
+4
-11
main.c
main.c
+29
-18
没有找到文件。
CriticalPath.h
浏览文件 @
c43bc431
#ifndef CRITICALPATH_H_
#ifndef CRITICALPATH_H_
#define CRITICALPATH_H_
#define CRITICALPATH_H_
//
//
// Include the C standard library header file here
// Include the C standard library header file here
//
//
#include <stdio.h>
#include <stdio.h>
//
//
// Other header files are included here
// Other header files are included here
//
//
#include "Stack.h"
#include "Stack.h"
//
//
// Define the data structure here
// Define the data structure here
//
//
...
@@ -27,7 +23,8 @@ typedef long BOOL;
...
@@ -27,7 +23,8 @@ typedef long BOOL;
#define FALSE 0
#define FALSE 0
// Edge (arc)
// Edge (arc)
typedef
struct
EdgeNode
{
typedef
struct
EdgeNode
{
int
vertex
;
// Vertex field. That is, the index of the vertex in the vertex array.
int
vertex
;
// Vertex field. That is, the index of the vertex in the vertex array.
int
weight
;
// Edge weights
int
weight
;
// Edge weights
struct
EdgeNode
*
nextedge
;
// Chain domain. Point to the next Edge (arc).
struct
EdgeNode
*
nextedge
;
// Chain domain. Point to the next Edge (arc).
...
@@ -36,31 +33,31 @@ typedef struct EdgeNode {
...
@@ -36,31 +33,31 @@ typedef struct EdgeNode {
}
EdgeNode
;
}
EdgeNode
;
// vertex
// vertex
typedef
struct
VexNode
{
typedef
struct
VexNode
const
char
*
name
;
// Use a string as the vertex's stored value. You can also think of it as the vertex's name.
{
// Use a string as the vertex's stored value. You can also think of it as the vertex's name.
const
char
*
name
;
EdgeNode
*
firstarc
;
// Pointing to the first side arc.
EdgeNode
*
firstarc
;
// Pointing to the first side arc.
int
Indegree
;
// indegree of vertex.
int
Indegree
;
// indegree of vertex.
}
VexNode
;
}
VexNode
;
// Graph. Use adjacency list storage
// Graph. Use adjacency list storage
typedef
struct
GraphList
{
typedef
struct
GraphList
{
VexNode
vexlist
[
MAX_VERTEX_NUM
];
// Vertex table
VexNode
vexlist
[
MAX_VERTEX_NUM
];
// Vertex table
int
length
;
// Vertex number
int
length
;
// Vertex number
}
GraphList
;
}
GraphList
;
//
//
// Declare the function here
// Declare the function here
//
//
void
InitGraph
(
GraphList
*
pGraphList
);
void
InitGraph
(
GraphList
*
pGraphList
);
void
DeleteGraph
(
GraphList
*
pGraphList
);
void
DeleteGraph
(
GraphList
*
pGraphList
);
void
FindInDegree
(
GraphList
*
pGraphList
);
void
FindInDegree
(
GraphList
*
pGraphList
);
int
CriticalPath
(
GraphList
*
pGraphList
);
int
CriticalPath
(
GraphList
*
pGraphList
);
void
OutputResult
(
GraphList
*
pGraphList
);
void
OutputResult
(
GraphList
*
pGraphList
);
//
//
// Declare global variables here
// Declare global variables here
//
//
...
...
Stack.c
浏览文件 @
c43bc431
...
@@ -30,8 +30,10 @@ int Push(Stack* pS, int Elem)
...
@@ -30,8 +30,10 @@ int Push(Stack* pS, int Elem)
//
//
// Stack full, push failed.
// 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
;
// Insert the element at the top of the stack
pS
->
buffer
[
pS
->
top
]
=
Elem
;
// Insert the element at the top of the stack
...
@@ -56,8 +58,10 @@ int Pop(Stack* pS)
...
@@ -56,8 +58,10 @@ int Pop(Stack* pS)
//
//
// The stack is empty and the pop fails
// The stack is empty and the pop fails
//
//
if
(
StackEmpty
(
pS
))
if
(
StackEmpty
(
pS
))
{
return
-
1
;
return
-
1
;
}
Elem
=
pS
->
buffer
[
pS
->
top
];
Elem
=
pS
->
buffer
[
pS
->
top
];
pS
->
top
--
;
pS
->
top
--
;
...
...
Stack.h
浏览文件 @
c43bc431
#ifndef STACK_H_
#ifndef STACK_H_
#define STACK_H_
#define STACK_H_
//
//
// Include the C standard library header file here
// Include the C standard library header file here
//
//
//
//
// Other header files are included here
// Other header files are included here
//
//
//
//
// Define the data structure here
// Define the data structure here
//
//
...
@@ -21,12 +16,13 @@
...
@@ -21,12 +16,13 @@
#define MAX_STACK_LENGTH 64 // Maximum length of stack
#define MAX_STACK_LENGTH 64 // Maximum length of stack
// Stack
// Stack
typedef
struct
Stack
{
typedef
struct
Stack
{
int
buffer
[
MAX_STACK_LENGTH
];
// Stack buffer
int
buffer
[
MAX_STACK_LENGTH
];
// Stack buffer
int
top
;
// Indicates the position at the top of the stack, not the number of elements in the stack
// Indicates the position at the top of the stack, not the number of elements in the stack
int
top
;
}
Stack
;
}
Stack
;
//
//
// Declare the function here
// Declare the function here
//
//
...
@@ -36,11 +32,8 @@ int Push(Stack* pS, int Elem);
...
@@ -36,11 +32,8 @@ int Push(Stack* pS, int Elem);
int
Pop
(
Stack
*
pS
);
int
Pop
(
Stack
*
pS
);
int
StackEmpty
(
Stack
*
pS
);
int
StackEmpty
(
Stack
*
pS
);
//
//
// Declare global variables here
// Declare global variables here
//
//
#endif
/* STACK_H_ */
#endif
/* STACK_H_ */
main.c
浏览文件 @
c43bc431
...
@@ -101,8 +101,10 @@ int CriticalPath(GraphList* pGraphList)
...
@@ -101,8 +101,10 @@ int CriticalPath(GraphList* pGraphList)
//
//
// Initializes an array of the latest occurrence times of events
// Initializes an array of the latest occurrence times of events
//
//
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
Vl
[
i
]
=
Ve
[
pGraphList
->
length
-
1
];
Vl
[
i
]
=
Ve
[
pGraphList
->
length
-
1
];
}
//
//
// TODO: Add the code here
// TODO: Add the code here
...
@@ -118,12 +120,14 @@ function:
...
@@ -118,12 +120,14 @@ function:
parameter:
parameter:
pGraphList -- Figure pointer
pGraphList -- Figure pointer
*/
*/
typedef
struct
Arc
{
typedef
struct
Arc
{
int
Weight
;
// The weight.
int
Weight
;
// The weight.
int
VexIndex
;
// The sequence of vertices adjacent to this vertex.
int
VexIndex
;
// The sequence of vertices adjacent to this vertex.
const
char
*
Name
;
// Side (arc) activity name
const
char
*
Name
;
// Side (arc) activity name
}
Arc
;
}
Arc
;
typedef
struct
VertexArrayEntry
{
typedef
struct
VertexArrayEntry
{
const
char
*
Name
;
// Name of the vertices.NULL indicates the end of the vertex sequence.
const
char
*
Name
;
// Name of the vertices.NULL indicates the end of the vertex sequence.
Arc
ArcArray
[
MAX_VERTEX_NUM
];
// Edge array.
Arc
ArcArray
[
MAX_VERTEX_NUM
];
// Edge array.
}
VertexArrayEntry
;
}
VertexArrayEntry
;
...
@@ -161,17 +165,22 @@ void InitGraph(GraphList* pGraphList)
...
@@ -161,17 +165,22 @@ void InitGraph(GraphList* pGraphList)
//
//
// Initializes the graph's adjacency list with the given data
// 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
)
// Name of the vertices.NULL indicates the end of the vertex sequence.
// Name of the vertices.NULL indicates the end of the vertex sequence.
if
(
NULL
==
VertexArray
[
i
].
Name
)
{
break
;
break
;
}
pGraphList
->
vexlist
[
i
].
name
=
VertexArray
[
i
].
Name
;
pGraphList
->
vexlist
[
i
].
name
=
VertexArray
[
i
].
Name
;
pEdgeNodePtr
=
&
pGraphList
->
vexlist
[
i
].
firstarc
;
// Makes the pointer point to the first edge of the vertex array (where the pointer was initialized)
// Makes the pointer point to the first edge of
for
(
j
=
0
;
j
<
MAX_VERTEX_NUM
;
j
++
)
// the vertex array (where the pointer was initialized)
pEdgeNodePtr
=
&
pGraphList
->
vexlist
[
i
].
firstarc
;
for
(
j
=
0
;
j
<
MAX_VERTEX_NUM
;
j
++
)
{
{
if
(
NULL
==
VertexArray
[
i
].
ArcArray
[
j
].
Name
)
if
(
NULL
==
VertexArray
[
i
].
ArcArray
[
j
].
Name
)
{
{
*
pEdgeNodePtr
=
NULL
;
*
pEdgeNodePtr
=
NULL
;
break
;
break
;
...
@@ -201,9 +210,9 @@ void DeleteGraph(GraphList* pGraphList)
...
@@ -201,9 +210,9 @@ void DeleteGraph(GraphList* pGraphList)
int
i
;
int
i
;
EdgeNode
*
pEdgeNode
;
EdgeNode
*
pEdgeNode
;
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
{
while
(
pGraphList
->
vexlist
[
i
].
firstarc
!=
NULL
)
while
(
pGraphList
->
vexlist
[
i
].
firstarc
!=
NULL
)
{
{
pEdgeNode
=
pGraphList
->
vexlist
[
i
].
firstarc
;
pEdgeNode
=
pGraphList
->
vexlist
[
i
].
firstarc
;
pGraphList
->
vexlist
[
i
].
firstarc
=
pEdgeNode
->
nextedge
;
pGraphList
->
vexlist
[
i
].
firstarc
=
pEdgeNode
->
nextedge
;
...
@@ -228,21 +237,21 @@ void OutputResult(GraphList* pGraphList)
...
@@ -228,21 +237,21 @@ void OutputResult(GraphList* pGraphList)
int
ee
,
el
;
// Temporary variable
int
ee
,
el
;
// Temporary variable
printf
(
"VertexSeq:
\t\t\t\t\t\t\t\t\t
"
);
printf
(
"VertexSeq:
\t\t\t\t\t\t\t\t\t
"
);
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
{
printf
(
"
\t
%s"
,
pGraphList
->
vexlist
[
i
].
name
);
printf
(
"
\t
%s"
,
pGraphList
->
vexlist
[
i
].
name
);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"An array of the earliest events to occur Ve:"
);
printf
(
"An array of the earliest events to occur Ve:"
);
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
{
printf
(
"
\t
%d "
,
Ve
[
i
]);
printf
(
"
\t
%d "
,
Ve
[
i
]);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"Event latest occurrentce time array Vl:
\t\t
"
);
printf
(
"Event latest occurrentce time array Vl:
\t\t
"
);
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
{
printf
(
"
\t
%d "
,
Vl
[
i
]);
printf
(
"
\t
%d "
,
Vl
[
i
]);
}
}
...
@@ -250,10 +259,11 @@ void OutputResult(GraphList* pGraphList)
...
@@ -250,10 +259,11 @@ void OutputResult(GraphList* pGraphList)
printf
(
"AdjacencyList:
\n
"
);
printf
(
"AdjacencyList:
\n
"
);
printf
(
"Vertex (VertexSubscript ActivityName Weight)...
\n
"
);
printf
(
"Vertex (VertexSubscript ActivityName Weight)...
\n
"
);
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
{
printf
(
"%s"
,
pGraphList
->
vexlist
[
i
].
name
);
printf
(
"%s"
,
pGraphList
->
vexlist
[
i
].
name
);
for
(
pEdgeNode
=
pGraphList
->
vexlist
[
i
].
firstarc
;
pEdgeNode
!=
NULL
;
pEdgeNode
=
pEdgeNode
->
nextedge
)
for
(
pEdgeNode
=
pGraphList
->
vexlist
[
i
].
firstarc
;
pEdgeNode
!=
NULL
;
pEdgeNode
=
pEdgeNode
->
nextedge
)
{
{
//
//
// Save the vertex index that the edge (arc) node pointer points to in k
// Save the vertex index that the edge (arc) node pointer points to in k
...
@@ -262,13 +272,14 @@ void OutputResult(GraphList* pGraphList)
...
@@ -262,13 +272,14 @@ void OutputResult(GraphList* pGraphList)
k
=
pEdgeNode
->
vertex
;
k
=
pEdgeNode
->
vertex
;
//
//
// 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 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
];
ee
=
Ve
[
i
];
el
=
Vl
[
k
]
-
pEdgeNode
->
weight
;
el
=
Vl
[
k
]
-
pEdgeNode
->
weight
;
if
(
ee
==
el
)
if
(
ee
==
el
)
{
{
printf
(
" -> (%2d [%s=%d])"
,
pEdgeNode
->
vertex
,
pEdgeNode
->
name
,
pEdgeNode
->
weight
);
printf
(
" -> (%2d [%s=%d])"
,
pEdgeNode
->
vertex
,
pEdgeNode
->
name
,
pEdgeNode
->
weight
);
pEdgeNode
->
isCritical
=
TRUE
;
pEdgeNode
->
isCritical
=
TRUE
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论