faqts : Computers : Programming : Languages : Delphi

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 21 people (57%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

Delphi: Datastructure: Tree: Binary: Create: Simple: How to create a binary tree in Delphi?

Oct 28th, 2003 23:01
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 29 October 2003 - 05:44 am --------------------

Delphi: Datastructure: Tree: Binary: Create: Simple: How to create a 
binary tree in Delphi?

---

Here is shown a simple definition of an empty binary tree.

---

program MyTreeCreateExample;

{$APPTYPE CONSOLE}

type
 treeP = ^treeR;

 treeR = record
   leftpointerP : treeP;
   mydataS : string;
   rightpointerP : treeP;
end;

begin
end.

---

It will define a node structure like the following:

 [left pointer - mydata - right pointer]

---
---

Here an example of the use of this binary tree.

---

program MyTreeCreateExample;

{$APPTYPE CONSOLE}

type
 treeP = ^treeR;

 treeR = record
  leftpointerP : treeP;
  mydataS : string;
  rightpointerP : treeP;
end;

var mytreeR : treeR;

begin
 mytreeR.leftpointerP := nil;
 mytreeR.mydataS := 'some info to store in this tree';
 mytreeR.rightpointerP := nil;
 //
 writeln( 'the current content of the data in this tree is ' + 
mytreeR.mydataS );
end.

---

If you compile this source code, it will show:

---

+---------------------------------------------------------------------+
|> dcc32.exe -Ic:\progra~1\borland\delphi7\lib                        |
|  -Rc:\progra~1\borland\delphi7\lib                                  |
|  -cc -q -v -h -w MyTreeCreateExample.pas                            |
|                                                                     |
|Borland Delphi Version 15.0                                          |
|Copyright (c) 1983,2002 Borland Software Corporation                 |
|25 lines, 0.07 seconds, 11048 bytes code, 1813 bytes data.           |
|                                                                     |
|> MyTreeCreateExample.exe                                            |
|                                                                     |
|the current content of the data in this tree is some info to store in|
|this tree                                                            |
|                                                                     |
|Press any key to continue . . .
+---------------------------------------------------------------------+

---
---

Book: see also:

---

[book: see also: author: Horowitz, Ellis / Sahni, Sartaj - p. 212 -
 'binary tree representations' - title: fundamentals of datastructures 
in Pascal - publisher: Computer Science Press - year: 1987 - ISBN 0-
88175-165-0]

---
---

Internet: see also:

---

BBCBASIC: Datastructure: Tree: Binary: Create: Simple: How to create a 
binary tree in BBCBASIC?
http://www.faqts.com/knowledge_base/view.phtml/aid/26122/fid/768

---

C#: Datastructure: Tree: Binary: Create: Simple: How to create a 
binary tree in C#?
http://www.faqts.com/knowledge_base/view.phtml/aid/26116/fid/791

---

C++: Datastructure: Tree: Binary: Create: Simple: How to create a 
binary tree in C++?
http://www.faqts.com/knowledge_base/view.phtml/aid/25923/fid/163

---

Java: Datastructure: Tree: Binary: Create: Simple: How to create a 
binary tree in Java?
http://www.faqts.com/knowledge_base/view.phtml/aid/26106/fid/165

----------------------------------------------------------------------