[fpc-pascal] How To write an enumerator for trees

Xiangrong Fang xrfang at gmail.com
Thu Mar 21 04:11:49 CET 2013


Hi,

I would like to add enumerator support for my TTreap implementation (
https://github.com/xrfang/fpcollection/blob/master/src/units/treap.pas).

The tree nodes are defined as:

      PNode = ^TNode;
      TNode = record
        Count: Cardinal;
        Key: TKey;
        Value: TValue;
        Priority: Cardinal;
        Left, Right: PNode;
      end;

Now I don't know how to write an enumerator for it.  I would like to
traverse the tree "In-Order", either from the left-most node or from the
right-most node, so that I can output nodes like:

      for n in MyTreap do WriteLn(n^.Key);

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130321/cdfb9ad0/attachment.html>


More information about the fpc-pascal mailing list