for(int i=0;i<vertexNum;i++)
{
Edge *E,*q;
E=adjlist[i].firstarc;
while(E)
{
q=E;
E=E->nextarc;
delete q;
}
}
}
template<class T>
Graph<T>::Graph(T a[],int n,int e){
int kind;
cout<<"请输入所需创建的图类型:"<<endl;
cout<<"-----1.无向图------"<<endl;
cout<<"-----2.有向图------"<<endl;
cin>>kind;
switch(kind){
case 1:
creatGraphU(a,n,e);break;
case 2:
creatGraphH(a,n,e);break;
default:
cout<<"输入错误!"<<endl;
}
}
template<class T>
void Graph<T>::creatGraphU(T a[],int n,int e){
Edge *E;
vertexNum=n;
arcNum=e;
for (int i=0;i<vertexNum;i++)
{
adjlist[i].vex=a[i];
adjlist[i].firstarc=NULL;
}
int j,w;
for (int k=0;k<arcNum;k++)
{
cout<<"请输入第"<<k+1<<"条弧的信息(格式为:顶点1 顶点2 权值)";
cin>>i>>j>>w;