#include<iostream.h> #include<stdlib.h> #include<strstrea.h> typedef int VertexType; typedef int WeightType; const int MaxVertexNum=10; const WeightType MaxValue=1000; const int MaxEdgeNum=100; typedef VertexType vexlist[MaxVertexNum]; typedef int adjmatrix[MaxVertexNum][MaxVertexNum]; void InitMatrix(adjmatrix GA,int k) {int i,j; for(i=0;i<MaxVertexNum;i++) for(j=0;j<MaxVertexNum;j++) if(i==j) GA[i][j]=0; else if(k) GA[i][j]=MaxValue; else GA[i][j]=0; }//初始化 void CreateMatrix(adjmatrix GA,int n,char*s,int k1,int k2) {istrstream sin(s); char c1,c2,c3; int i,j; WeightType w; sin>>c1; if(k1==0&&k2;==0) do{sin>>c1>>i>>c2>>j>>c3; GA[i][j]=GA[j][i]=1; sin>>c1; if(c1==')') break; } while(1); else if(k1==0&&k2;!=0) do{sin>>c1>>i>>c2>>j>>c3>>w; GA[i][j]=GA[j][i]=w; sin>>c1; if(c1==')') break; }while(1); else if(k1!=0&&k2;==0) do{sin>>c1>>i>>c2>>j>>c3; GA[i][j]=1; sin>>c1; if(c1==')') break; } while(1); else if(k1!=0&&k2;!=0) do{sin>>c1>>i>>c2>>j>>c3>>w; GA[i][j]=w; sin>>c1; if(c1==')') break; }while(1); }//根据一个图的边集生成图的邻接矩阵 int maxOutDegree(adjmatrix GA,int n) {int i,j,max=0; for(i=0;i<n;i++){ int k=0; for(j=0;j<n;j++) if(GA[i][j]!=0&&GA;[i][j]!=MaxValue) k++; if(k>max) max=k; } return max; }//图中所有顶点的最大出度数 void main() {int n,k1=0,k2=0; cout<<"输入待处理图的顶点数:"; cin>>n; cout<<"输入图的有无向和有无权选择:"; cin>>k1>>k2; adjmatrix ga; InitMatrix (ga,k2); cout<<"输入图的边集:"; char*a=new char[100]; cin>>a; CreateMatrix(ga,n,a,k1,k2); cout<<"图中所有顶点的最大出度数为:"<<maxOutDegree (ga,n); }
- 粉丝: 0
- 资源: 1
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助