資源描述:
《關(guān)鍵路徑c語(yǔ)言程序源代碼.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、#include#include#includeusingnamespacestd;#defineMAX_VERTEX_NUM20#defineSTACK_INIT_SIZE100#defineSTACKINCREAMENT10#defineOK1#defineERROR0#defineOVERFLOW-1#defineMaxname20typedefstructArcNode{intadjvex;structArcNode*nextarc;intdut;
2、}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*)malloc(STACK_
3、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*)realloc(S.base,(S.stac
4、ksize+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[Maxname];intCreatGraph(ALGrap
5、h&G){inti,j;intv1,v2;ArcNode*q;printf("請(qǐng)輸入頂點(diǎn)個(gè)數(shù):");scanf("%d",&G.vexnum);for(i=0;i>G.vertices[i].data;}printf("請(qǐng)輸入邊數(shù):
6、");scanf("%d",&G.arcnum);printf("請(qǐng)分別輸入邊的信息:");for(j=0;jdut);G.vertices[v2].indegree++;q->nextarc=NULL;q->adjvex=v2;q->nextarc=G.vertices[v1].fir
7、starc;G.vertices[v1].firstarc=q;}for(i=0;i8、ces[i].indegree)Push(S,i);}count=0;while(StackEmpty(S)){Pop(S,j);Push(T,j);++count;for(p=G.vertices[j].firstarc;p;p=p->nextarc){k=p->adjvex;if(--G.vertices[k].indegree==0)Push(S,k);if(ve[