C and Cpp

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDesktop ProgrammingC and Cpp

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old November 21st, 2010, 06:26 AM
ma129 ma129 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 1 ma129 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 14 sec
Reputation Power: 0
Binary tree in C

hey for my final project m looking for simple binary tree code

Reply With Quote
  #2  
Old May 27th, 2013, 04:05 AM
payroll.12pay payroll.12pay is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2013
Posts: 6 payroll.12pay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 39 sec
Reputation Power: 0
Code for creation of Binary tree

void insert(node ** tree, int val) {
node *t = NULL;
if(!(*tree)) {
t = (node *)malloc(sizeof(node));
t->left = t->right = NULL;
t->data = val;
*tree = t;
return;
}

if(val < (*tree)->data) {
insert(&(*tree)->left, val);
} else if(val > (*tree)->data) {
insert(&(*tree)->right, val);
}
}

Last edited by payroll.12pay : May 27th, 2013 at 04:57 AM.

Reply With Quote
  #3  
Old December 7th, 2016, 02:54 AM
dishagandhi dishagandhi is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Dec 2016
Location: Ahmedabad
Posts: 52 dishagandhi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 40 m 42 sec
Reputation Power: 1
A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element. The "root" pointer points to the topmost node in the tree.
The left and right pointers recursively point to smaller "subtrees" on either side. A null pointer represents a binary tree with no elements -- the empty tree.
The formal recursive definition is: a binary tree is either empty (represented by a null pointer), or is made of a single node, where the left and right pointers (recursive definition ahead) each point to a binary tree.

Below I am providing you the very basic example of Binary Search Tree.

Code:
#include <iostream>

using namespace office;

struct Body{
       int data;
       Body* RightSide;
       Body* LeftSide;
       };
       
int main(){
   Body* Root = NULL;
   Body* RightHand = NULL;
   Body* LeftHand = NULL;
   Body* Current = NULL;
   
    Root = new Body;
    RightHand = new Body;
    LeftHand = new Body;
    Current = new Body;
    
    
    Root->data = 1;
    Root->LeftHand = LeftHand;
    Root->RightHand = RightHand;
    
    RightHand->data = 3;
    RightHand->LeftSide = NULL;
    RightHand->RightSide = NULL;
    
    LeftHand->data = 2;
    LeftHand->LeftSide = NULL;
    LeftHand->RightSide = NULL;
    
    Current = Root;
    
                  while(Current != NULL){
                        cout << Current->data << endl;
                        Current = Current->Left;
                        }
                        
    
    
    system("PAUSE");
}

Reply With Quote
Reply

Viewing: Tutorialized ForumsDesktop ProgrammingC and Cpp > Binary tree in C


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap