欢迎来到天天文库
浏览记录
ID:53965422
大小:116.50 KB
页数:9页
时间:2020-04-11
《数据结构用C语言课程设计之图的深度遍历与广度遍历.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、数据结构用C语言课程设计之图的深度遍历与广度遍历#include#include#definemaxsize1000#definen100typedefstruct{charvexs[n];intarcs[n][n];intnum;}G;typedefstruct{intdata[maxsize];intfront,rear;}V;voidGInit(G*L){L->num=0;}intGVexs(G*L){return(L->num);}voidGCrea
2、te(G*L){inti,j;GInit(L);printf("请输入顶点数目:");scanf("%d",&L->num);printf("请输入各顶点:");for(i=0;inum;i++){fflush(stdin);scanf("%c",&L->vexs[i]);}printf("请输入各顶点边的关系(1是有关0是无关):");for(i=0;inum;i++){for(j=0;jnum;j++){scanf("%d",&L->arcs[i][j])
3、;}}}voidGOut(GL){inti,j;printf("图的顶点数目为:%d",L.num);printf("图的各顶点的信息为:");for(i=0;i4、){intv1;mark[qidian]=1;printf("%c",g.vexs[qidian]);for(v1=0;v15、vfront=0;sq->rear=0;}intQueueIsEmpty(Vsq){if(sq.rear==sq.front)return(1);elsereturn(0);}intQueueFront(Vsq,int*e){if(QueueIsEmpt6、y(sq)){printf("queueisempty!");return0;}else{*e=sq.data[(sq.front)];return1;}}intQueueIn(V*sq,intx)//{if(sq->front==(sq->rear+1)%maxsize){printf("queueisfull!");return0;}else{sq->data[sq->rear]=x;sq->rear=(sq->rear+1)%maxsize;return(1);}}intQueue7、Out(V*sq){if(QueueIsEmpty(*sq)){printf("queueisempty!");return0;}else{sq->front=(sq->front+1)%maxsize;return1;}}voidBFS(Gg,intv,intmark[]){intv1,v2;Vq;QueueInit(&q);QueueIn(&q,v);mark[v]=1;printf("%c",g.vexs[v]);while(QueueIsEmpty(q)==0){QueueFront8、(q,&v1);QueueOut(&q);for(v2=0;v2
4、){intv1;mark[qidian]=1;printf("%c",g.vexs[qidian]);for(v1=0;v15、vfront=0;sq->rear=0;}intQueueIsEmpty(Vsq){if(sq.rear==sq.front)return(1);elsereturn(0);}intQueueFront(Vsq,int*e){if(QueueIsEmpt6、y(sq)){printf("queueisempty!");return0;}else{*e=sq.data[(sq.front)];return1;}}intQueueIn(V*sq,intx)//{if(sq->front==(sq->rear+1)%maxsize){printf("queueisfull!");return0;}else{sq->data[sq->rear]=x;sq->rear=(sq->rear+1)%maxsize;return(1);}}intQueue7、Out(V*sq){if(QueueIsEmpty(*sq)){printf("queueisempty!");return0;}else{sq->front=(sq->front+1)%maxsize;return1;}}voidBFS(Gg,intv,intmark[]){intv1,v2;Vq;QueueInit(&q);QueueIn(&q,v);mark[v]=1;printf("%c",g.vexs[v]);while(QueueIsEmpty(q)==0){QueueFront8、(q,&v1);QueueOut(&q);for(v2=0;v2
5、vfront=0;sq->rear=0;}intQueueIsEmpty(Vsq){if(sq.rear==sq.front)return(1);elsereturn(0);}intQueueFront(Vsq,int*e){if(QueueIsEmpt
6、y(sq)){printf("queueisempty!");return0;}else{*e=sq.data[(sq.front)];return1;}}intQueueIn(V*sq,intx)//{if(sq->front==(sq->rear+1)%maxsize){printf("queueisfull!");return0;}else{sq->data[sq->rear]=x;sq->rear=(sq->rear+1)%maxsize;return(1);}}intQueue
7、Out(V*sq){if(QueueIsEmpty(*sq)){printf("queueisempty!");return0;}else{sq->front=(sq->front+1)%maxsize;return1;}}voidBFS(Gg,intv,intmark[]){intv1,v2;Vq;QueueInit(&q);QueueIn(&q,v);mark[v]=1;printf("%c",g.vexs[v]);while(QueueIsEmpty(q)==0){QueueFront
8、(q,&v1);QueueOut(&q);for(v2=0;v2
此文档下载收益归作者所有