91 lines
1.8 KiB
C++
91 lines
1.8 KiB
C++
#include "topologytest.h"
|
|
#include <iostream>
|
|
TopologyTest::TopologyTest(int nodeN):nodeN(nodeN),access(nodeN)
|
|
{
|
|
|
|
}
|
|
|
|
TopologyTest::~TopologyTest()
|
|
{
|
|
|
|
}
|
|
|
|
bool TopologyTest::start(const QList<QPair<int,int> >& linkage)
|
|
{
|
|
//先建立所有的连接关系
|
|
QHash<int,QVector<int> > arch;
|
|
for(
|
|
QList<QPair<int,int> >::const_iterator ite=linkage.begin();
|
|
ite!=linkage.end();
|
|
ite++
|
|
)
|
|
{
|
|
// int f=(*ite).first-1;
|
|
// int s=(*ite).second-1;
|
|
// std::cout<<f<<" to "<<s<<std::endl;
|
|
arch[(*ite).first-1].push_back((*ite).second-1);
|
|
arch[(*ite).second-1].push_back((*ite).first-1);
|
|
}
|
|
//开始找
|
|
bool flag=true;
|
|
// QList<int> keys=arch.keys();
|
|
for(int outer=0;
|
|
outer<this->nodeN;
|
|
outer++)
|
|
{
|
|
if(!flag)
|
|
{
|
|
break;
|
|
}
|
|
for(int i=0;i<this->nodeN;i++)
|
|
{
|
|
this->access[i]=-100;
|
|
}
|
|
int n=outer;
|
|
this->next(n,arch);
|
|
//检查一下
|
|
for(int i=0;i<this->nodeN;i++)
|
|
{
|
|
if(this->access[i]==-100)
|
|
{
|
|
flag=false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
if(!flag)
|
|
{
|
|
std::cout<<"no!!"<<std::endl;
|
|
for(int i=0;i<this->access.length();i++)
|
|
{
|
|
if(this->access.at(i)==-100)
|
|
{
|
|
std::cout<<i+1<<",";
|
|
}
|
|
}
|
|
std::cout<<std::endl;
|
|
}
|
|
// else
|
|
// {
|
|
// std::cout<<"yes!!"<<std::endl;
|
|
// }
|
|
return flag;
|
|
|
|
}
|
|
|
|
void TopologyTest::next(int start,QHash<int,QVector<int> > &arch)
|
|
{
|
|
if(this->access[start]==100)
|
|
return;
|
|
// std::cout<<"fw "<<start<<std::endl;
|
|
this->access[start]=100;
|
|
QVector<int> nextNode=arch[start];
|
|
for(int i=0;i<nextNode.length();i++)
|
|
{
|
|
|
|
this->next(nextNode.at(i),arch);
|
|
}
|
|
}
|
|
|