Faqts : Business : Programming : Shopping For You : C++

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

58 of 93 people (62%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

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

Aug 25th, 2009 00:10
Joe Bloggs, Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 07 October 2003 - 10:23 pm --------------------

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

---

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

---

#include <iostream.h>

struct tree {
  struct tree *leftpointerP;
  struct tree *rightpointerP;
  void *mydata;
};


main() {
}

---

It will define a node structure like the following:

 [left pointer - mydata - right pointer]

---
---

Here an example of the use of this binary tree.

---

#include <iostream.h>

struct tree {
  struct tree *leftpointerP;
  struct tree *rightpointerP;
  string mydataS;
};

struct tree *rootp;

main() {

 rootp = ( struct tree * ) malloc ( sizeof( struct tree ) ); // new 
(=create space in memory for your tree)

 cout << "the current content of the leftpointer in this tree is "; 
rootp->leftpointerP; // show the content of your leftpointer

 cout << "\n";

 cout << "the current content of the data in this tree is "; rootp-
>mydataS; // show the current content of your data

 cout << "\n";

 cout << "the current content of the leftpointer in this tree is "; 
rootp->rightpointerP; // show the content of your rightpointer

 cout << "\n";
}

---

If you compile this source code, it will show:

+------------------------------------------------------+
|> bcc32.exe -Ic:\borland\bcc55\include                |
|  -Lc:\borland\bcc55\lib mytreeexample.cpp            |
|                                                      |
|> mytreeexample.exe                                   |
|                                                      |
|the current content of the leftpointer in this tree is|
|                                                      |
|the current content of the data in this tree is       |
|                                                      |
|the current content of the leftpointer in this tree is|
|                                                      |
|Press any key to continue . . .                       |
+------------------------------------------------------+

---
---

Book: see also:

---

[book: Flamig, Bryan - practical datastructures in C++ - p. 5 -
 'treating datastructures in the abstract' - 
http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?
userid=2TFIGCDXI3&isbn=0471009555&itm=1]

---

[book: Schildt, Herbert - advanced C - p. 68 - 'binary trees' - 
http://www.amazon.com/exec/obidos/tg/detail/-
/0078812089/qid=1067386182/sr=8-1/ref=sr_8_1/103-2842924-9105401?
v=glance&n=507846]

---
---

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

---

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

---

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

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

======================================

http://www.attorneyslawyersdirectory.com
http://www.findattorneyslawyers.com
http://www.goodlawyersattorneys.com
http://www.professionallawyersattorneys.com
http://www.bestprofessionallawyers.com
http://www.americalawyersattorneys.com
http://www.availablelawyers.com
http://www.lawyersattorneyslist.com
http://www.lawyersattorneysfirm.com
http://www.originallawyers.com
http://www.lawyersgulf.com
http://www.lawyersband.com
http://www.lawyersdatacenter.com
http://www.lawyerstigers.com
http://www.lawcliff.com
http://www.tidylawyers.com
http://www.lawyersblock.com
http://www.californialawyersattorneys.com
http://www.chicagoattorneyslawyers.com
http://www.goodcalifornialawyers.com
http://www.lawyersattorneysfaqs.com
http://www.divorceattorneyslawyers.com
http://www.duiattorneyslawyers.com
http://www.personalinjurylawyerslist.com
http://www.injurylawyersattorneys.com
http://www.dwilawyersattorneys.com
http://www.healthbigboss.com
http://www.healthdohealth.com
http://www.healthcass.com
http://www.healthsilence.com
http://www.healthpicnic.com
http://www.blackmesothelioma.com
http://www.affordablelawyersattorneys.com
http://www.pickarticles.com
http://www.pickarticle.com
http://www.bloodyarticles.com
http://www.healthment.com
http://www.healthbyhealth.com
http://www.ehealthebooks.com
http://www.bestproductsofhealth.com
http://www.dietlosingweight.com
http://www.americanehealth.com
http://www.healthydepartment.com
http://www.medicalehealth.com
http://www.healthservicescenter.com
http://www.ehealthenews.com
http://www.ehealthdept.com
http://www.benefitshealthcenter.com
http://www.toplawyersattorneys.com 
http://www.healthxhealth.com
http://mesotheliomakiller.com
http://www.healthinhealth.com
http://www.booksyshop.com
http://www.mesotheliomaout.com
http://www.mesotheliomadown.com
http://www.qwesz.com
http://americanahost.com
http://www.healthfirewall.com
http://www.healthbodyguard.com
http://www.flathealth.com
http://www.computerstan.com
http://www.financestan.com
http://www.technologystan.com
http://www.zobab.com
http://www.businessian.com
http://www.tarabiza.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.hantira.com
http://www.mantofa.com
http://www.tantofa.com
http://www.fantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.yamot.com
http://www.mozmar.com
http://www.uploadarticles.com
http://www.articlesfreedirectory.com
http://www.articlesxarticles.com
http://www.shikapika.com
http://www.ganazat.com
http://www.stakoza.com
http://www.stupidarticles.com
http://www.damima.com
http://www.halazona.com
http://www.best-cheap-web-hosting.com

======================================