Published on February 4, 2014 by mycodeschool

See complete series on data structures here:

In this lesson, we have implemented binary search tree in C/C++. We have written a simple program to create a binary search tree of integers and search an element in it.

See source code here:

Lesson on dynamic memory allocation:

For practice problems and more, visit: www.mycodeschool.com

Like us on Facebook: www.facebook.com/MyCodeSchool

Follow us on twitter: twitter.com/mycodeschool

Leave a Reply

281 Comments on "Binary search tree – Implementation in C/C++"

Notify of
avatar

Sanskriti Upadhyay
Guest
Sanskriti Upadhyay
18 days 22 hours ago

Why do u put a bracket while dynamically allocating new… Such as.. Here u have written bstnode*=new bstnode() ;Why do we put there circular paranthesis… Everywhere else whe just writeBstnode*=new bstnode;

Soumya Samirana
Guest
Soumya Samirana
24 days 5 hours ago

When I run the code given in github, I get the result as not found for all the numbers which we inserted. Anyone can help ?

LetTheWritersWrite
Guest
LetTheWritersWrite
1 month 1 day ago

Fantastic lesson. I just want to point out that the addressing can be simplified so much by making a class instead in C++ that will save the pain of referencing addresses and whatnot.

Coda jj9
Guest
Coda jj9
1 month 15 days ago

Hello very good video man .Can you write somewhere full code in c , I would be very thankful 😀

Coda jj9
Guest
Coda jj9
1 month 15 days ago

my mail is     daca.stojanovic98@gmail.com

Shashank Gupta
Guest
Shashank Gupta
1 month 19 days ago

In the Insert function, the GetNewNode function should be returned. As:if(root == NULL){ return GetNewNode(data);}

Zeeshan Ul Haq
Guest
Zeeshan Ul Haq
1 month 21 days ago

luve u buddy..

Soumyadeep Chakraborty
Guest
Soumyadeep Chakraborty
1 month 26 days ago

I have one doubt,…..how do you insert the address of the left/right child in the parent node?

Arda Tunccekic
Guest
Arda Tunccekic
1 month 28 days ago

Very sad. RIP…

TECH NATION
Guest
TECH NATION
2 months 19 hours ago

let us assume we have created the root node and after it we have created the left child and linked the root node .currently root has the address of the left child and at the last when we return root then actually it is returning address of left child which is get copied to global root beacuse of root=insert(root,10) that means we have lost the address of our root node …IS THIS TRUE…

WHITE KNIGHT
Guest
WHITE KNIGHT
2 months 5 days ago

hi,here I mistakenly used else if in the last condition without an if statement it showed that the control reached the end of non void functioncould you help me.what is the problem?

1 2 3 23
wpDiscuz