| 174 | */ |
| 175 | template <typename Index, typename IndexVector> |
| 176 | void treePostorder(Index n, IndexVector& parent, IndexVector& post) |
| 177 | { |
| 178 | IndexVector first_kid, next_kid; // Linked list of children |
| 179 | Index postnum; |
| 180 | // Allocate storage for working arrays and results |
| 181 | first_kid.resize(n+1); |
| 182 | next_kid.setZero(n+1); |
| 183 | post.setZero(n+1); |
| 184 | |
| 185 | // Set up structure describing children |
| 186 | Index v, dad; |
| 187 | first_kid.setConstant(-1); |
| 188 | for (v = n-1; v >= 0; v--) |
| 189 | { |
| 190 | dad = parent(v); |
| 191 | next_kid(v) = first_kid(dad); |
| 192 | first_kid(dad) = v; |
| 193 | } |
| 194 | |
| 195 | // Depth-first search from dummy root vertex #n |
| 196 | postnum = 0; |
| 197 | internal::nr_etdfs(n, parent, first_kid, next_kid, post, postnum); |
| 198 | } |
| 199 | |
| 200 | } // end namespace internal |
| 201 |
no test coverage detected