Binary Trees in Forth
Author Message
Binary Trees in Forth

Here is a simple binary tree algorithm that I whipped out in my spare
time.  The code to build the tree fits in 16 lines (one block) of
Forth.  With the addition of the test code it only takes 2 blocks.  I'm
not going to make any claims this time, but I THINK it's all ANS Forth.

: AddTreeNode HERE 0 , 0 , 0 , ;

: LeftChild 1 CELLS + ;
: RightChild 2 CELLS + ;

: Prefix

: Postfix

: InFix

CREATE TestTree
AddTreeNode ASCII x OVER ! TestTree LeftChild !
AddTreeNode ASCII * OVER ! TestTree RightChild !

TestTree Prefix CR
TestTree Postfix CR
TestTree Infix CR

--
Guns don't kill people...bullets do.

Sent via Deja.com http://www.*-*-*.com/

Mon, 31 Mar 2003 03:00:00 GMT
Binary Trees in Forth
Quote:

> Here is a simple binary tree algorithm that I whipped out in my spare
> time.  The code to build the tree fits in 16 lines (one block) of
> Forth.  With the addition of the test code it only takes 2 blocks.  I'm
> not going to make any claims this time, but I THINK it's all ANS Forth.

> : AddTreeNode HERE 0 , 0 , 0 , ;

> : LeftChild 1 CELLS + ;
> : RightChild 2 CELLS + ;

> : Prefix

> : Postfix

> : InFix

> CREATE TestTree
> AddTreeNode ASCII x OVER ! TestTree LeftChild !
> AddTreeNode ASCII * OVER ! TestTree RightChild !

> TestTree Prefix CR
> TestTree Postfix CR
> TestTree Infix CR

> --
> Guns don't kill people...bullets do.

> Sent via Deja.com http://www.deja.com/

Tue, 01 Apr 2003 03:00:00 GMT
Binary Trees in Forth

Quote:

Oh.  When I said "no claims" I meant "no claims about ANS
compatibility".  Last time I posted code (my UTF-8 CODEC) I claimed it
was fully ANS only to find out that DEFER wasn't part of the ANS
specs.  I think all of the words I used this time were ANS but I'm not

As for the other stuff (copyright, copyleft, warrentee ect.) I'll
this.  This is public domain code.  Anyone can do whatever they want
with it except claim that they wrote it.  There are no expressed or
implied warrentees or guarantees.  (In other words if ya haven't paid
me for writing it, don't sue me if it doesn't work.)  Beyond that I
have tested it and I sincerely believe the code works as described.

Quote:

> > Here is a simple binary tree algorithm that I whipped out in my
spare
> > time.  The code to build the tree fits in 16 lines (one block) of
> > Forth.  With the addition of the test code it only takes 2 blocks.
I'm
> > not going to make any claims this time, but I THINK it's all ANS
Forth.

> > : AddTreeNode HERE 0 , 0 , 0 , ;

> > : LeftChild 1 CELLS + ;
> > : RightChild 2 CELLS + ;

> > : Prefix

> > : Postfix

> > : InFix

> > CREATE TestTree
> > ASCII + AddTreeNode !
> > AddTreeNode ASCII x OVER ! TestTree LeftChild !
> > AddTreeNode ASCII * OVER ! TestTree RightChild !

> > TestTree Prefix CR
> > TestTree Postfix CR
> > TestTree Infix CR

> > --
> > Guns don't kill people...bullets do.

> > Sent via Deja.com http://www.deja.com/

--
Guns don't kill people...bullets do.

Sent via Deja.com http://www.deja.com/