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
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.*-*-*.com/
Before you buy.



Mon, 31 Mar 2003 03:00:00 GMT  
 Binary Trees in Forth
No claims!  What about Copyright, Copyleft, Warrantee, and Guarantee?
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/
> Before you buy.



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

Quote:

> No claims!  What about Copyright, Copyleft, Warrantee, and Guarantee?



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
making any claims about it.

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/
> > Before you buy.

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

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 01 Apr 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Self-Adjusting Binary Search Trees (Splay Trees)

2. Self-Adjusting Binary Search Trees (Splay Trees)

3. AVL Tree,Binary Tree,Sorting..

4. Pointers and Binary Trees!

5. Binary trees in gawk

6. Binary tree

7. Binary Trees - SmallTalk

8. Binary Search Trees

9. Binary trees

10. Balanced binary tree in Haskell

11. Balanced binary tree in Haskell

12. drawing textual representations of binary trees

 

 
Powered by phpBB® Forum Software