9都市を直結したグラフを作ろうとしています。「ショートパス」機能でこの問題が発生しています。「ベクトル反復子に互換性がありません」というエラーが表示され続け、それを理解できません。助けてください。ありがとう
これは機能です:
void City::shortPath( vector<City*> & cities )
{
queue<City*> q;
q.push(this);
for( unsigned int i = 0; i < cities.size(); i++ )
{
cities[i]->cityDistance = -1;
cities[i]->visited1 = false;
}
q.front()->visited1 = true;
q.front()->cityDistance = 0;
while( !q.empty() )
{
City * v = q.front();
if( v->neighbor1.size() != 0 )
{
for( unsigned int i = 0; i < v->neighbor1.size(); i++ )
{
City * z = v->neighbor1[i];
q.push( z );
if( z->visited1 == false )
{
v->neighbor1[i]->cityDistance = v->cityDistance + 1;
v->neighbor1[i]->previous1.push_back( *v );
v->neighbor1[i]->visited1 = true;
}
}
}
q.pop();
}
}
そして、これがメインです:
int main()
{
City * NewDelhi = &City( "New Delhi" );
City * HongKong = &City("Hong Kong");
City * Washington = &City("Washington");
City * Dublin = &City("Dublin");
City * Lisbon = &City("Lisbon");
City * Vienna = &City("Vienna");
City * Santiago = &City("Santiago");
City * RioDeJaneiro = &City("RioDeJaneiro");
City * Berlin = &City( "Berlin" );
City * NewYork = &City( "NewYork" );
vector<City*> vector1;
vector1.push_back(HongKong);
vector1.push_back(NewDelhi);
vector1.push_back(Washington);
vector1.push_back(Dublin);
vector1.push_back(Lisbon);
vector1.push_back(Vienna);
vector1.push_back(Santiago);
vector1.push_back(RioDeJaneiro);
vector1.push_back(Berlin);
vector1.push_back(NewYork);
(*HongKong).neighbor1.push_back( NewDelhi );
(*NewDelhi).neighbor1.push_back( Washington);
(*Washington).neighbor1.push_back( Dublin );
(*Dublin).neighbor1.push_back( Lisbon );
(*Lisbon).neighbor1.push_back( Vienna );
(*Vienna).neighbor1.push_back( Santiago );
(*Santiago).neighbor1.push_back( RioDeJaneiro );
(*RioDeJaneiro).neighbor1.push_back( Berlin );
(*Berlin).neighbor1.push_back( NewYork );
(*NewYork).neighbor1.push_back( HongKong );
(*NewYork).shortPath( vector1 );