想找一下这段C语言的错误,该怎么改。(详细代码和报错如下)
代码:#include<iostream>#include<stdio.h>#include<string>#include<queue>#include<string.h>#defineINFINITY0X7fffffff#defineTRUE1#defineFALSE0#defineOK1#defineERROR0usingnamespacestd;#defineMAX_VERTEX_NUM30typedefcharInfoType;typedefintStatus;typedefintBoolean;typedefstringVertexType;typedefenum{DG,DN,UDG,UDN}GraphKind;typedefstructArcNode///弧(邻接表){intadjvex;///当前弧指向的顶点intinfo;///权值structArcNode*nextarc;///下一条当前顶点为出度的弧}ArcNode;typedefstructVNode///点(邻接表){VertexTypedata;///结点名ArcNode*firstarc;///该点的第一条出边}VNode,AdjList[MAX_VERTEX_NUM];typedefstruct///图(邻接表){AdjListvertices;///点的邻接表(数组)intvexnum,arcnum;intkind;}ALGraph;Status(*VisitFunc_2)(ALGraphG,intv);voidArcAdd_sort(ALGraph&G,intv1,intv2,intw)///从大到小顺序建立邻接表{ArcNode*p,*h,*q;p=newArcNode;p->adjvex=v2;p->info=w;p->nextarc=NULL;h=q=***.vertices[v1].firstarc;if(q==NULL)***.vertices[v2].firstarc=p;else{if(p->adjvex>q->adjvex)///邻接表按结点序号从大到小排列{p->nextarc=q;***.vertices[v2].firstarc=p;}else{while(***.vertices[v2].firstarc!=NULL&&q->nextarc!=NULL&&p->adjvex<q->adjvex){h=q;q=q->nextarc;}if(q->nextarc==NULL&&p->adjvex<q->adjvex)q->nextarc=p;else{p->nextarc=q;h->nextarc=p;}}}}voidArcAdd(ALGraph&G,intv1,intv2,intw)///加边{ArcNode*p,*q;p=newArcNode;p->adjvex=v2;p->info=w;p->nextarc=NULL;q=***.vertices[v1].firstarc;if(q==NULL)***.vertices[v1].firstarc=p;///若第一条依附v2顶点的弧还未存在,新加入的边作为第一条依附弧else///否则顺着链表向后查找{while(q->nextarc!=NULL)q=q->nextarc;q->nextarc=p;}}intLocateVex_2(ALGraphG,stringname)///获取结点标号{for(inti=0;i<***.vexnum;i++)if(name==***.vertices[i].data)returni;return-1;}StatusCreateDG_2(ALGraph&G)///邻接表(建立无权有向图){printf("建立无权有向图,请依次输入总结点数、总边数:\n");scanf("%d%d",&***.vexnum,&***.arcnum);printf("请为从1至n个结点命名:\n");for(inti=0;i<***.vexnum;i++)cin>>***.vertices[i].data,***.vertices[i].firstarc=NULL;stringv1,v2;printf("请输入%d组由左指向右的有向边:\n",***.arcnum);for(intk=0;k<***.arcnum;k++){cin>>v1>>v2;inti=LocateVex_2(G,v1);///获取标号intj=LocateVex_2(G,v2);ArcAdd(G,i,j,1);}returnOK;}StatusCreateDN_2(ALGraph&G)///邻接表(建立带权有向网){printf("建立带权有向网,请依次输入总结点数、总边数:\n");scanf("%d%d",&***.vexnum,&***.arcnum);printf("请为从1至n个结点命名:\n");for(inti=0;i<***.vexnum;i++)cin>>***.vertices[i].data,***.vertices[i].firstarc=NULL;stringv1,v2;intw;printf("请输入%d组由左指向右的有向边与边权:\n",***.arcnum);for(intk=0;k<***.arcnum;k++){cin>>v1>>v2>>w;inti=LocateVex_2(G,v1);///获取标号intj=LocateVex_2(G,v2);ArcAdd(G,i,j,w);}returnOK;}StatusCreateUDG_2(ALGraph&G)///邻接表(建立无权无向图){printf("建立无权无向图,请依次输入总结点数、总边数:\n");scanf("%d%d",&***.vexnum,&***.arcnum);printf("请为从1至n个结点命名:\n");for(inti=0;i<***.vexnum;i++)cin>>***.vertices[i].data,***.vertices[i].firstarc=NULL;stringv1,v2;printf("请输入%d组相互依附的两结点:\n",***.arcnum);for(intk=0;k<***.arcnum;k++){cin>>v1>>v2;inti=LocateVex_2(G,v1);///获取标号intj=LocateVex_2(G,v2);ArcAdd(G,i,j,1);///无向边ArcAdd(G,j,i,1);}returnOK;}StatusCreateUDN_2(ALGraph&G)///邻接表(建立带权无向网){printf("建立带权无向网,请依次输入总结点数、总边数:\n");scanf("%d%d",&***.vexnum,&***.arcnum);printf("请为从1至n个结点命名:\n");for(inti=0;i<***.vexnum;i++)cin>>***.vertices[i].data,***.vertices[i].firstarc=NULL;stringv1,v2;intw;printf("请输入%d组相互依附的两结点与边权:\n",***.arcnum);for(intk=0;k<***.arcnum;k++){cin>>v1>>v2>>w;inti=LocateVex_2(G,v1);///获取标号intj=LocateVex_2(G,v2);ArcAdd(G,i,j,w);///无向边ArcAdd(G,j,i,w);}returnOK;}intFirstAdjVex(ALGraphG,intv){if(***.vertices[v].firstarc)return***.vertices[v].firstarc->adjvex;return-1;}intNextAdjVex(ALGraphG,intv,intw){ArcNode*p=***.vertices[v].firstarc;while(p->adjvex!=w&&p->nextarc!=NULL)p=p->nextarc;if(p->nextarc==NULL)return-1;returnp->nextarc->adjvex;}voidDFS_2(ALGraphG,intv)///邻接表DFS{visited[v]=TRUE;VisitFunc_2(G,v);for(intw=FirstAdjVex(G,v);w>=0;w=NextAdjVex(G,v,w))if(!visited[w])DFS_2(G,w);}voidDFSTraverse_2(ALGraphG,Status(*Visit)(ALGraphG,intv)){VisitFunc_2=Visit;printf("请输入深度优先搜索起始结点:\n");for(intv=0;v<***.vexnum;v++)visited[v]=FALSE;stringst;cin>>st;inttmp=LocateVex_2(G,st);printf("深度优先搜索遍历序列:\n");DFS_2(G,tmp);for(intv=0;v<***.vexnum;v++)if(!visited[v])DFS_2(G,v);printf("\n");}voidBFSTraverse_2(ALGraphG,Status(*Visit)(ALGraphG,intv))///邻接表BFS{for(intv=0;v<***.vexnum;v++)visited[v]=FALSE;queue<int>Q;printf("请输入广度优先搜索起始结点:\n");stringst;cin>>st;printf("广度优先搜索遍历序列:\n");inttemp=LocateVex_2(G,st);Visit(G,temp);***.push(temp);visited[temp]=TRUE;while(!***.empty()){inttmp=***.front();***.pop();for(intw=FirstAdjVex(G,tmp);w>=0;w=NextAdjVex(G,tmp,w)){if(!visited[w]){visited[w]=TRUE;Visit(G,w);***.push(w);}}}for(intv=0;v<***.vexnum;v++)///剩余连通分量{if(!visited[v]){visited[v]=TRUE;Visit(G,v);***.push(v);while(!***.empty()){inttmp=***.front();***.pop();for(intw=FirstAdjVex(G,tmp);w>=0;w=NextAdjVex(G,tmp,w)){if(!visited[w]){visited[w]=TRUE;Visit(G,w);***.push(w);}}}}}printf("\n");}voidPrintGraph(ALGraphG)///输出邻接表{cout<<"图的创建完成,该图的邻接表表示为:"<<endl;ArcNode*p;for(inti=0;i<***.vexnum;i++){if(***.vertices[i].firstarc==NULL)cout<<i<<":"<<***.vertices[i].data<<"-->NULL"<<endl;else{p=***.vertices[i].firstarc;cout<<i<<":"<<***.vertices[i].data<<"-->";while(p->nextarc!=NULL){cout<<p->adjvex<<"-->";p=p->nextarc;}cout<<p->adjvex<<"-->NULL"<<endl;}}}StatusCreateGraph_2(ALGraph&G)///邻接表{printf("请输入建图类型(1:无权有向图、2:带权有向网、3:无权无向图、4:带权无向网):\n");scanf("%d",&***.kind);///输入图的种类switch(***.kind-1){caseDG:returnCreateDG_2(G);caseDN:returnCreateDN_2(G);caseUDG:returnCreateUDG_2(G);caseUDN:returnCreateUDN_2(G);default:returnERROR;}}Statusvisit_2(ALGraphG,intv)///邻接表遍历{cout<<***.vertices[v].data<<'';}intmain(){while(true){MGraphG1;CreateGraph(G1);///邻接矩阵DFSTraverse(G1,visit);///深搜邻接矩阵BFSTraverse(G1,visit);///广搜邻接矩阵ALGraphG2;///邻接表CreateGraph_2(G2);PrintGraph(G2);///输出邻接表DFSTraverse_2(G2,visit_2);///邻接表深搜BFSTraverse_2(G2,visit_2);///邻接表广搜}}报错:网志问答在浏览187次收到腾讯网的热心用户鬼姬numb关于红色警戒想找一下这段C语言的错误,该怎么改。(详细代码和报错如下)的提问,关于这些疑难问题,进行了深入的分析。得到了网志问答众多网友的支持,得到了如下解决方案,摘录了部分优质回答,如对此有任何好的意见,欢迎大家进行探讨共同解决!
详细问题描述及疑问:期待您的答案,千言万语,表达不了我的感激之情,我已铭记在心
!
本页链接:http://www.oxrm.com/question/1656032103214074