I have a function which operates on a nested linked list. The function is the following:
void DoLiana(void) {
PlotPointer plot;
TreePointer tree;
plot = FirstPlot;
while (plot != nullptr) {
tree = plot->FirstTree;
while (tree != nullptr) {
if (tree->isLiana) {
if (tree->attachedTree == nullptr && TestForLianaAttach(plot, tree))
DoLianaAttachement(plot, tree);
}
tree = tree->next;
}
plot = plot->next;
}
}
Because this type of iterations happen multiple times in my code I am looking for a way to make the iteration more compact and expressive. I read that in C++11 there are ranged based for loops that iterate over a set. Would this construct be applicable in this situation? Or are there other possible ways to perform these iterations?
Aucun commentaire:
Enregistrer un commentaire