欢迎来到天天文库
浏览记录
ID:34500993
大小:76.50 KB
页数:7页
时间:2019-03-07
《邻接表存储深度优先遍历》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#include#defineTRUE1#defineFALSE0#defineOK1typedefintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNode{intdata;ArcNode*firstarc;}VNode,AdjList[MAX_VERTEX_NUM];
2、typedefstruct{AdjListvertices;intvexnum,arcnum;}ALGraph;//locatestatusLocateVex(ALGraphG,intvex){for(inti=0;i3、++){scanf("%d",&G.vertices[i].data);G.vertices[i].firstarc=NULL;}printf("输入弧");intv1,v2;for(intj=0;j4、f(v2=G.vertices[k].data)countvex[temp_2]++;}p_1=(ArcNode*)malloc(sizeof(ArcNode));p_1->adjvex=temp_2;p_1->nextarc=G.vertices[temp_1].firstarc;G.vertices[temp_1].firstarc=p_1;p_2=(ArcNode*)malloc(sizeof(ArcNode));p_2->adjvex=temp_1;p_2->nextarc=G.vertices[temp_2].firstarc;G.vertices[temp_2].firstarc=5、p_2;}returnOK;}//TraversingGraphintVisited[MAX_VERTEX_NUM];statusVisitFunc(ALGraphG,intv){printf("%d",G.vertices[v].data);returnOK;}voidDFS(ALGraphG,intv){Visited[v]=TRUE;VisitFunc(G,v);intlocation=LocateVex(G,v);for(intw=0;w6、){//VisitFunc=Visit;for(intv=0;v#include#defineTRUE1#defineFALSE0#defineOK1type7、defintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNode{intdata;ArcNode*firstarc;}VNod
3、++){scanf("%d",&G.vertices[i].data);G.vertices[i].firstarc=NULL;}printf("输入弧");intv1,v2;for(intj=0;j4、f(v2=G.vertices[k].data)countvex[temp_2]++;}p_1=(ArcNode*)malloc(sizeof(ArcNode));p_1->adjvex=temp_2;p_1->nextarc=G.vertices[temp_1].firstarc;G.vertices[temp_1].firstarc=p_1;p_2=(ArcNode*)malloc(sizeof(ArcNode));p_2->adjvex=temp_1;p_2->nextarc=G.vertices[temp_2].firstarc;G.vertices[temp_2].firstarc=5、p_2;}returnOK;}//TraversingGraphintVisited[MAX_VERTEX_NUM];statusVisitFunc(ALGraphG,intv){printf("%d",G.vertices[v].data);returnOK;}voidDFS(ALGraphG,intv){Visited[v]=TRUE;VisitFunc(G,v);intlocation=LocateVex(G,v);for(intw=0;w6、){//VisitFunc=Visit;for(intv=0;v#include#defineTRUE1#defineFALSE0#defineOK1type7、defintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNode{intdata;ArcNode*firstarc;}VNod
4、f(v2=G.vertices[k].data)countvex[temp_2]++;}p_1=(ArcNode*)malloc(sizeof(ArcNode));p_1->adjvex=temp_2;p_1->nextarc=G.vertices[temp_1].firstarc;G.vertices[temp_1].firstarc=p_1;p_2=(ArcNode*)malloc(sizeof(ArcNode));p_2->adjvex=temp_1;p_2->nextarc=G.vertices[temp_2].firstarc;G.vertices[temp_2].firstarc=
5、p_2;}returnOK;}//TraversingGraphintVisited[MAX_VERTEX_NUM];statusVisitFunc(ALGraphG,intv){printf("%d",G.vertices[v].data);returnOK;}voidDFS(ALGraphG,intv){Visited[v]=TRUE;VisitFunc(G,v);intlocation=LocateVex(G,v);for(intw=0;w6、){//VisitFunc=Visit;for(intv=0;v#include#defineTRUE1#defineFALSE0#defineOK1type7、defintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNode{intdata;ArcNode*firstarc;}VNod
6、){//VisitFunc=Visit;for(intv=0;v#include#defineTRUE1#defineFALSE0#defineOK1type
7、defintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNode{intdata;ArcNode*firstarc;}VNod
此文档下载收益归作者所有