求数据结构中关键路径的算法
#包含
#包含
#包含
#包含
类型结构arc cell {
int adj; /*顶点关系类型。 用1表示邻接,用0表示不邻接*/
}ArcCell,* * adj矩阵; /*邻接矩阵/
类型def struct type {
char data[3]; /*顶点值*/
int info; /*弧长*
结构类型*下一步; /*顶点的下一个指针*
}VertexType;
类型定义结构{
VertexType *vexs; /*顶点向量*
adj矩阵Arcs; /*邻接矩阵/
int vexnum,arcnum; /*图的顶点数和边数*/
} m图形;
/* * * * * * *8* /
typedef int Status;
#define STACK_INIT_SIZE 50
类型def int elemtype;
类型结构堆栈/*堆栈类型*/
{
ElemType *base;
ElemType *top;
int stacksize;
int length;
}SqStack,*Stack;
voidinitstack (堆栈* s )/*初始化堆栈) /
{
*s=(sqstack* ) malloc ) sizeof (sqstack );
(s )-base=) elemtype * (malloc ) stack_init_size*sizeof ) elemtype );
if (! (s )-base ) exit(-1 );
(s )-top=) s )-base;
(s ) -堆叠大小=堆叠_ init _ size;
(s ) -长度=0;
}
statusdestroystack (堆栈* s )/*销毁堆栈/
{
free () s )-base );
free () ) s );
返回1;
}
statusstackempty(sqstacks )/*判断是否为堆栈空) /
{
if(s.top==s.base ) return 1;
else
返回0;
}
将void push (堆栈* s,元素类型e )/*数据推入堆栈(/
{
(if ((s )-top-) (s )-base=)-stacksize () ) ) ) ) ) ) 65
{
(s )-base=(elemtype* ) realloc ) ) s )-base,
((s ) -堆叠大小10 ) ) sizeof ) elemtype );
if (! (s )-base ) exit(-1 );
(s )-top=)-base ) ) s ) -堆叠大小;
(s ) -堆叠大小=10;
}
* () s )-top )=e;
(s ) -长度;
}
删除status pop (堆栈* s,元素类型* e )/*堆栈顶部元素(/
{
if () s )-top==) s )-base ) return 0;
*e=* (() s ) -顶1 );
- () s ) -长度;
(s )-top--;
返回1;
}
/* * * * * * * * * * * *
voidinitgraph(mgraph*g )/*初始图(/
{ int i,nu,mu;
输入printf((n顶点数和)边)弧的数量。 ) );
扫描(' % d % d )、nu、mu );
g-arcs=(arccell** ) malloc ) nu * sizeof (arc cell * );
for(I=0; I
g-arcs[I]=(arccell* ) malloc (nu * sizeof ) arccell );
g-vexs=(vertextype* ) malloc ) nu * sizeof (vertextype ); /*指定顶点空间*
G-vexnum=nu; G-arcnum=mu; /*图的顶点数和边数*/
}
语音图形(m graph * g )/*销毁图/
{ int i;
自由(g-vexs );
for(I=0; ivexnum; I )
free(g-ARCS[I];
}
语音图形(m graph * g,int i,VertexType e ) )。
{if(I0|||ig-vexnum ) return;
G-vexs[i].next=e.next;
g-vexs [ I ].info=http://doc.wendoc.com;
strcpy(g-vexs[I].data,e.data );
}
确定v1在intlocate(mgraphg,VertexType v1 )/*图表顶点的位置(/
{ int i;
for(I=0; I
if(strcmp(V1.data,G.vexs[i].data )==0)返回I;
返回- 1;
}
voidcreateund(mgraph*g )/)使用数组(邻接矩阵)和邻接表进行有向图) /
{int i,j,k,*p,d,w;
VertexType v1、v2、*q2、*q;
p=(int* ) malloc ) g-vexnum*sizeof ) int );
for(I=0; ivexnum; I ) p[i]=0;
for(I=0; ivexnum; I(/)初始邻接表) /
{for(j=0; jvexnum; j ) G-arcs[i][j].adj=0; }
宣传广告