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

Xiangrong Fang xrfang at gmail.com
Thu Mar 21 09:32:50 CET 2013


I have read this. My question is not about how to write enumerator, but how to do this for TREEs

Thanks


发送自魅族MX

-------- 原始邮件 --------
发件人:Mattias Gaertner <nc-gaertnma at netcologne.de>
时间:3月21日 15:39 周四
收件人:fpc-pascal at lists.freepascal.org
主题:Re: [fpc-pascal] How To write an enumerator for trees

>On Thu, 21 Mar 2013 11:11:49 +0800
>Xiangrong Fang <xrfang at gmail.com> wrote:
>
>> 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);
>
>See here:
>
>http://wiki.freepascal.org/for-in_loop#Declaring_enumerators
>
>Mattias
>_______________________________________________
>fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>http://lists.freepascal.org/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130321/0cab5068/attachment.html>


More information about the fpc-pascal mailing list