删除下列代码中的注释#include <iostream> #define MVNum 100//最大顶点数 using namespace std; typedef struct{ int vexs[MVNum];//顶点表 int arcs[MVNum][MVNum];//邻接矩阵 int vexnum,arcnum; }AMGraph; void Create_V(AMGraph &G,int name){ int pos=++G.vexnum; G.vexs[pos-1]=name;//存入点名 for(int i=1;i<=pos;i++){//点所在的行列清零 G.arcs[i-1][pos-1]=0; G.arcs[pos-1][i-1]=0; } } void Create_Arc(AMGraph &G,int h,int k){ G.arcs[h-1][k-1]=G.arcs[k-1][h-1]=1;//点与对称点都归1 } void Out_Graph(AMGraph G){ cout<<"0 ";//开头输出0 for(int i=1;i<G.vexnum;i++) cout<<G.vexs[i-1]<<" ";//输出所有点名 cout<<G.vexs[G.vexnum-1]<<endl; for(int i=1;i<=G.vexnum;i++){//输出所有弧 cout<<G.vexs[i-1]<<" "; for(int j=1;j<G.vexnum;j++){ cout<<G.arcs[i-1][j-1]<<" "; } cout<<G.arcs[i-1][G.vexnum-1]<<endl; } } void Calculate(int m,int n){ AMGraph G; G.vexnum=G.arcnum=0; for(int i=1;i<=m;i++) Create_V(G,i);//构造前n个顶点 for(int i=1;i<=n;i++){//构造n条边 int h,k; cin>>h>>k;//输入左右顶点 Create_Arc(G,h,k);//构造边 } int new_point;//新顶点 cin>>new_point; Create_V(G,new_point);//新顶点入图 Out_Graph(G);//输出图 } int main(){ int m,n; while(cin>>m>>n&&m!=0&&n!=0){//每次处理一行数据 Calculate(m,n); } return 0; }
时间: 2024-01-26 12:02:39 浏览: 65
以下是删除了注释的代码:
#include <iostream>
#define MVNum 100
using namespace std;
typedef struct{
int vexs[MVNum];
int arcs[MVNum][MVNum];
int vexnum,arcnum;
}AMGraph;
void Create_V(AMGraph &G,int name){
int pos=++G.vexnum;
G.vexs[pos-1]=name;
for(int i=1;i<=pos;i++){
G.arcs[i-1][pos-1]=0;
G.arcs[pos-1][i-1]=0;
}
}
void Create_Arc(AMGraph &G,int h,int k){
G.arcs[h-1][k-1]=G.arcs[k-1][h-1]=1;
}
void Out_Graph(AMGraph G){
cout<<"0 ";
for(int i=1;i<G.vexnum;i++) cout<<G.vexs[i-1]<<" ";
cout<<G.vexs[G.vexnum-1]<<endl;
for(int i=1;i<=G.vexnum;i++){
cout<<G.vexs[i-1]<<" ";
for(int j=1;j<G.vexnum;j++){
cout<<G.arcs[i-1][j-1]<<" ";
}
cout<<G.arcs[i-1][G.vexnum-1]<<endl;
}
}
void Calculate(int m,int n){
AMGraph G;
G.vexnum=G.arcnum=0;
for(int i=1;i<=m;i++) Create_V(G,i);
for(int i=1;i<=n;i++){
int h,k;
cin>>h>>k;
Create_Arc(G,h,k);
}
int new_point;
cin>>new_point;
Create_V(G,new_point);
Out_Graph(G);
}
int main(){
int m,n;
while(cin>>m>>n&&m!=0&&n!=0){
Calculate(m,n);
}
return 0;
}
阅读全文