欢迎来到天天文库
浏览记录
ID:13370385
大小:76.50 KB
页数:7页
时间:2018-07-22
《邻接表存储,深度优先遍历》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#defineTRUE1#defineFALSE0#defineOK1typedefintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNode{intdata;ArcNode*firstarc;}VNode,AdjLi
2、st[MAX_VERTEX_NUM];typedefstruct{AdjListvertices;intvexnum,arcnum;}ALGraph;//locatestatusLocateVex(ALGraphG,intvex){for(inti=0;i3、tf("输入顶点");for(inti=0;i4、vexnum;k++){if(v1=G.vertices[k].data)countvex[temp_1]++;if(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=5、temp_1;p_2->nextarc=G.vertices[temp_2].firstarc;G.vertices[temp_2].firstarc=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=LocateV6、ex(G,v);for(intw=0;w7、);DFSTraverse(G);printf("");returnOK;}#include#include#defineTRUE1#defineFALSE0#defineOK1typedefintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNo8、de{intdata;ArcNode*firstarc;}VNod
3、tf("输入顶点");for(inti=0;i4、vexnum;k++){if(v1=G.vertices[k].data)countvex[temp_1]++;if(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=5、temp_1;p_2->nextarc=G.vertices[temp_2].firstarc;G.vertices[temp_2].firstarc=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=LocateV6、ex(G,v);for(intw=0;w7、);DFSTraverse(G);printf("");returnOK;}#include#include#defineTRUE1#defineFALSE0#defineOK1typedefintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNo8、de{intdata;ArcNode*firstarc;}VNod
4、vexnum;k++){if(v1=G.vertices[k].data)countvex[temp_1]++;if(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=
5、temp_1;p_2->nextarc=G.vertices[temp_2].firstarc;G.vertices[temp_2].firstarc=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=LocateV
6、ex(G,v);for(intw=0;w7、);DFSTraverse(G);printf("");returnOK;}#include#include#defineTRUE1#defineFALSE0#defineOK1typedefintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNo8、de{intdata;ArcNode*firstarc;}VNod
7、);DFSTraverse(G);printf("");returnOK;}#include#include#defineTRUE1#defineFALSE0#defineOK1typedefintstatus;//Membertype#defineMAX_VERTEX_NUM20intcountvex[MAX_VERTEX_NUM];//与此顶点相关的弧的个数typedefstructArcNode{intadjvex;structArcNode*nextarc;}ArcNode;typedefstructVNo
8、de{intdata;ArcNode*firstarc;}VNod
此文档下载收益归作者所有