Binary Tree
Author Message
Binary Tree

Does anyone know where I can get some simple code to create a binary tree
structure in Pascal? Thanks in advance.

--

Listen to my tunes!
http://www.*-*-*.com/

Wed, 18 Jun 1902 08:00:00 GMT
Binary Tree
im in the same boat :o)

craig

Quote:
> Does anyone know where I can get some simple code to create a binary tree
> structure in PASCAL? Thanks in advance.

> --

> Listen to my tunes!
> http://www.mp3.com/rawlyn

Wed, 18 Jun 1902 08:00:00 GMT
Binary Tree

Quote:
> im in the same boat :o)
> > Does anyone know where I can get some simple code to create a binary tree
> > structure in PASCAL? Thanks in advance.

This may help both of you:

program BINARY_TREE;      { Binary Tree with Pointers Example }
const EOD = -98765;                       { End-of-Data value }
type BTT  = ^NODE;                      { define pointer type }
NODE = record                   { template for tree node }
NUM    : integer;                         { node value }
LP, RP : BTT                                { pointers }
end;
var  CURR : integer;                    { current input value }
TREE : BTT;                           { pointer variable }
MORE : boolean;                     { input data control }
procedure INSERT (var WORK : BTT);{ insert value(s) into tree }
{ This procedure is Recursive... }
var  NEWP : BTT;                      { local working pointer }
begin
if WORK = Nil then
begin                          { insert element into tree }
New (NEWP);               { obtain new pointer location }
with NEWP^ do
begin
NUM := CURR;                { add value to new node }
LP  := Nil;        { set new node pointers to "Nil" }
RP  := Nil; RP  := Nil
end;
WORK := NEWP                { move local node into tree }
end
else   if CURR < WORK^.NUM then      { belongs on left side }
INSERT (WORK^.LP)              { walk left node(s) }
else                         { belongs on right side }
INSERT (WORK^.RP)             { walk right node(s) }
end;                                           { of procedure }
procedure PRINTTREE (FILLED : BTT);         { print tree data }
begin
if FILLED <> nil then                   { process some data }
begin
PRINTTREE (FILLED^.LP);          { process left node(s) }
write (FILLED^.NUM:5);   { write out current node value }
PRINTTREE (FILLED^.RP)          { process right node(s) }
end
end;                                           { of procedure }
begin                                             { Main Line }
MORE := true; TREE := Nil;                     { initialize }
writeln ('Enter random integers; terminate with -98765');
while MORE do
if CURR = EOD then MORE := false          { end of data }
else INSERT (TREE)                       { process data }
end;                                           { of while }
writeln ('Sorted input numbers:');                { heading }
PRINTTREE (TREE);                  { walk & print tree data }
writeln; writeln ('Finis...')
end.

Wed, 18 Jun 1902 08:00:00 GMT
Binary Tree

Quote:

>im in the same boat :o)

>craig

>> Does anyone know where I can get some simple code to create a binary tree
>> structure in PASCAL? Thanks in advance.

>> --

>> Listen to my tunes!
>> http://www.mp3.com/rawlyn

I'll look into it!

This binary tree:
For what purpose do you want 2 use it?
Cause I find this one off the more sensefull quaetions!

Heinrich

Wed, 18 Jun 1902 08:00:00 GMT
Binary Tree

Quote:

>>im in the same boat :o)

>>craig

>>> Does anyone know where I can get some simple code to create a binary
tree
>>> structure in PASCAL? Thanks in advance.

>>> --

>>> Listen to my tunes!
>>> http://www.mp3.com/rawlyn

>I'll look into it!

>This binary tree:
> For what purpose do you want 2 use it?
>Cause I find this one off the more sensefull quaetions!

>Heinrich

Hi there!

I've looked into it and my tutoriul now inclueds a part to teach trees!

In the tutoriul it's under pointers!

homes.arealcity.com/heinrichshomepage/

See I keep my promises!

Heinrich

Wed, 18 Jun 1902 08:00:00 GMT
Binary Tree
Hi,

Quote:
> homes.arealcity.com/heinrichshomepage/

Despite the fact that you are constantly plugging it, your homepage "doesn't

- Sebastian

--
This posting was manufactured to meet critical quality standards.
If you believe the posting has a manufacturing defect, please call our
Quality Management Department at ++49-800-BASTISOFT.

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages
 11. Binary Trees