It's not a bug. My recursive function goes from left to right of the vector of children. To emulate that behavior using an explicit stack like I have, to process the element I want first, it has to be put on the stack last and the element I want processed last has to be added first.

Here, consider this original code which I think behaves as it should :

Code:

void search_tree(tree *root, particle *p, vector<tree*> & stack) {
if (!visited.insert(root).second) {cout << "Duplicate\n"; return;}
/* Is this a Delaunay node? */
if (root->del == 0) { /* If no... */
/* Is the point, p, outside the tetrahedron in the current node? */
if (inside_tetra(root->t, p) == -1) { /* If yes... */
return;
}
/* Is this node a leaf? */
if (root->children.empty()) { /* If yes... */
/* Is this leaf occupied? */
//if (root->occ == 0) { /* If no... */
root->occ = 1;
stack.push_back(root);
return;
//} else if (root->occ == 1) /* If yes... */
//return;
} else { /* Else iterate over children */
for (vector<tree*>::iterator it = root->children.begin(); it < root->children.end(); it++) {
search_tree(*it, p, stack);
}
}
} else if (root->del == 1) { /* If yes... */
for (vector<tree*>::iterator it = root->children.begin(); it < root->children.end(); it++) {
search_tree(*it, p, stack);
}
}
return;
}

The occ field is now rendered irrelevant due to the set visited scanning for duplicates so I commented it out. This is slightly old outdated code.