Код: Выделить всё
Stack stack;
stack.push(start);
start->visited = true;
while (!stack.isEmpty()) {
Block* curr = stack.peek();
if(curr == end){
paths[pathCount] = stack;
pathCount++;
stack.pop();
}
else{
bool valid = false;
for(int i = 0; i < curr->adjCount; i++){
if(!curr->adj[i].visited){
Block* next = &curr->adj[i];
valid = true;
for(int j = 0; j < next->adjCount; j++){
if(next->adj[j].visited){
valid = false;
break;
}
}
if(valid){
next->visited = true;
stack.push(next);
break;
}
}
}
if(!valid){
for(int i = 0; i < curr->adjCount; i++){
curr->adj[i].visited = false;
}
stack.pop();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... inite-loop