欢迎来到天天文库
浏览记录
ID:37727329
大小:32.00 KB
页数:4页
时间:2019-05-29
《关键路径c语言程序源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#includeusingnamespacestd;#defineMAX_VERTEX_NUM20#defineSTACK_INIT_SIZE100#defineSTACKINCREAMENT10#defineOK1#defineERROR0#defineOVERFLOW-1#defineMaxname20typedefstructArcNode{intadjvex;structArcNode*nextarc;i
2、ntdut;}ArcNode;typedefstructVNode{intindegree;chardata;ArcNode*firstarc;}VNode,AdjList[MAX_VERTEX_NUM];typedefstruct{AdjListvertices;intvexnum,arcnum;}ALGraph;typedefstruct{char*base;char*top;intstacksize;}SqStack;intInitStack(SqStack&S){S.base=(char*)m
3、alloc(STACK_INIT_SIZE*sizeof(char));if(!S.base)exit(OVERFLOW);S.top=S.base;S.stacksize=STACK_INIT_SIZE;returnOK;};intStackEmpty(SqStackS){if(S.top==S.base)returnERROR;elsereturnOK;}intPush(SqStack&S,inte){if(S.top-S.base>=S.stacksize){S.base=(char*)real
4、loc(S.base,(S.stacksize+STACKINCREAMENT)*sizeof(char));if(!S.base)exit(OVERFLOW);S.top=S.base+S.stacksize;S.stacksize+=STACKINCREAMENT;}*S.top++=e;returnOK;}intPop(SqStack&S,int&e){if(S.top==S.base)returnERROR;e=*--S.top;returne;}intve[Maxname],vl[Maxna
5、me];intCreatGraph(ALGraph&G){inti,j;intv1,v2;ArcNode*q;printf("请输入顶点个数:");scanf("%d",&G.vexnum);for(i=0;i>G.vert
6、ices[i].data;}printf("请输入边数:");scanf("%d",&G.arcnum);printf("请分别输入边的信息:");for(j=0;jdut);G.vertices[v2].indegree++;q->nextarc=NULL;q->adj
7、vex=v2;q->nextarc=G.vertices[v1].firstarc;G.vertices[v1].firstarc=q;}for(i=0;i8、or(i=0;inextarc){k=p->adjvex;if(--G.vertices[k].indegree==0)Push(S,k);if(ve[
8、or(i=0;inextarc){k=p->adjvex;if(--G.vertices[k].indegree==0)Push(S,k);if(ve[
此文档下载收益归作者所有