我有一个需要将递归算法转换为迭代过程的问题。CvSeq 是一种树形结构。其中contour->h_next给出了同一级别中的下一个节点。 contour->v_next给出了下一级别中的下一个轮廓(子节点)。
void helperParseCurves(CvSeq* contour, int level) {
if(contour->h_next != NULL) {
helperParseCurves(contour->h_next, level);
}
if(contour->v_next != NULL) {
helperParseCurves(contour->v_next, level+1);
}
//Process the nodes in contour
for(int i=0; i<contour->total; i++){
CvPoint* p = CV_GET_SEQ_ELEM(CvPoint, contour, i);
//Paint the point p
}
}
我希望将这个逻辑重构为迭代算法。有什么建议吗?