What was it, I'm using these reverse iterators to add nodes from a graph to a stack for iterative traversal. My real code looks like this :
Code:
void search_tree(tree *root, particle *p, vector<tree*> & leaves) {
set<tree*> visited;
stack<tree*> traversal;
traversal.push(root);
while (!traversal.empty()) {
tree *curr = traversal.top();
if (!visited.insert(curr).second) {
traversal.pop();
continue;
}
if (curr->del == 0) {
if (inside_tetra(curr->t, p) == -1) {
traversal.pop();
continue;
}
if (curr->children.empty()) {
leaves.push_back(curr);
traversal.pop();
continue;
} else {
//for (auto it = curr->children.end(); it < curr->children.end(); ++it)
//traversal.push(*it);
for (auto it = curr->children.crbegin(); it != curr->children.crend(); ++it)
traversal.push(*it);
continue;
}
} else if (curr->del == 1) {
//for (auto it = curr->children.begin(); it < curr->children.end(); ++it)
//traversal.push(*it);
for (auto it = curr->children.crbegin(); it != curr->children.crend(); ++it)
traversal.push(*it);
continue;
}
}
return;
}
I only decided to add the children in reverse order because the way my code works, the way in which children are processed matters for the output and I was trying to make sure my iterative solution matches exactly to my recursive implementation which I've been using as a reference. The outputs match though. I was just trying to optimize the code.