You have an empty vector / array / queue CvSeq *. Have a pointer / pointer in it, first pointing to its beginning (where the very first element will be).
Start with the root of the tree and add its h_next and v_next to the vector.
Then, while the index is less than the number of pointers in vector-1, take the vector [index] h_next and v_next, add them to the end of the vector and the do ++ pointer.
As a result, you get pointers to all nodes of the tree in this vector / array / whatever.
Then you just iterate over it, draw things and much more.
Alexey Frunze
source share