@extends('layouts.TreeContainerLibrary') @section('styles') @stop @section('panel-heading') Descendant Element Iterators @stop @section('content')

Descendant element iterators iterate over a node's descendants. There are three types of descendant element iterators for the tree container library, the pre_order_iterator, post_order_iterator, and level_order_iterator. The pre_order_iterators and post_order_iterators are bi-directional iterators, while the level_order_iterators are forward-only iterators. The three types of descendant element iterators are described below. Illustrations to the right show how the three types of descendant iterators traverse a tree.

The descendant element iterators have the same interface and operations as the child element iterators. So you can perform all the same operations as on the child iterator. Unlike the inserting and erasing operations in the STL, performing an insert, or clear operation on an iterator's underlying node does not invalidate that iterator. This is because by performing one of these operations on an iterator's underlying node affects the node's children only. This does not mean that performing on of these operations will not have an effect on the transversal. Inserting or removing nodes via an iterator will most likely alter future iterations, especially if the iterator is a pre_order_iterator or level_order_iterator. With a post_order_iterator, the children have already been traversed before visiting the parent, so performing an insert or clear on the iterator will not effect the future iterations.

The only operations in the tree containers which return descendant element iterators are those operations which return the beginning and end of the iterators, as shown below.

Figure 1

pre_order_iterator

Pre order iterator

Figure 2

post_order_iterator

Post order iterator

Figure 3

level_order_iterator

Level order iterator
@stop