Board index » delphi » Binary Tree

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.mp3.com/rawlyn

 

Re:Binary Tree


im in the same boat :o)

craig

Quote
Minimum <mini...@chplayers.freeserve.co.uk> wrote in message

news:81jton$qn6$1@newsg1.svr.pol.co.uk...
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

Re: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
    begin                             { read data & load tree }
      read (CURR);                        { read a data value }
      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.

Re:Binary Tree


Quote
Craig Hennessey wrote in message <82c20q$n9...@newsg3.svr.pol.co.uk>...
>im in the same boat :o)

>craig

>Minimum <mini...@chplayers.freeserve.co.uk> wrote in message
>news:81jton$qn6$1@newsg1.svr.pol.co.uk...
>> 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?
 E-mail me than I'll help you!
Cause I find this one off the more sensefull quaetions!

Heinrich

Re:Binary Tree


Quote
NLHG wrote in message <82ekep$4d...@ctb-nnrp1.saix.net>...

>Craig Hennessey wrote in message <82c20q$n9...@newsg3.svr.pol.co.uk>...
>>im in the same boat :o)

>>craig

>>Minimum <mini...@chplayers.freeserve.co.uk> wrote in message
>>news:81jton$qn6$1@newsg1.svr.pol.co.uk...
>>> 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?
> E-mail me than I'll help you!
>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!
Go download it at my web-site:

In the tutoriul it's under pointers!

homes.arealcity.com/heinrichshomepage/

See I keep my promises!

Heinrich

Re:Binary Tree


Hi,

on Tue, 07 Dec 1999 at 20:59:51 o'clock, NLHG wrote:

Quote
> homes.arealcity.com/heinrichshomepage/

Despite the fact that you are constantly plugging it, your homepage "doesn't
work", that is, I always get 404 File Not Found.

 - 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.

Other Threads