Cześć
Potrzebuje zamienić wywołania rekurencyjne w tym algorytmie https://github.com/hellogcc/circuit-finding-algorithm na iteracyjne
np dla metody
Template < int N >
void CircuitFinder < N >::unblock( int U )
{
Blocked[ U - 1 ] = false;
while( !B[ U - 1 ].empty() ) {
int W = B[ U - 1 ].front();
B[ U - 1 ].pop_front();
if( Blocked[ W - 1 ] ) {
unblock( W );
}
}
}
wykorzystałem w tym celu kojejkę
template < int N >
void CycleFinder < N >::unblock( int U )
{
_queue < int > q;
q.push( U );
while( !q.empty() )
{
int Z = q.pop();
Blocked[ Z - 1 ] = false;
while( !B[ Z - 1 ].empty() )
{
int W = B[ Z - 1 ].top();
B[ Z - 1 ].pop();
if( Blocked[ W - 1 ] )
{
q.push( W );
}
}
}
}
Niestety nie mogę sobie poradzić z tą metodą
template < int N >
bool CircuitFinder < N >::circuit( int V )
{
bool F = false;
Stack.push_back( V );
Blocked[ V - 1 ] = true;
for( int W: AK[ V - 1 ] ) {
if( W == S ) {
output();
F = true;
} else if( W > S && !Blocked[ W - 1 ] ) {
F = circuit( W );
}
}
if( F ) {
unblock( V );
} else {
for( int W: AK[ V - 1 ] ) {
auto IT = std::find( B[ W - 1 ].begin(), B[ W - 1 ].end(), V );
if( IT == B[ W - 1 ].end() ) {
B[ W - 1 ].push_back( V );
}
}
}
Stack.pop_back();
return F;
}