dev-resources.site
for different kinds of informations.
Binary Tree Implementation
Published at
8/23/2024
Categories
dsa
beginners
algorithms
programming
Author
Ankit Rattan
Well! One by one I will be posting all the relevant codes required for basic DSA.
Starting with Binary Tree, there are various videos explaing what Binary tree is all about, well here is one line which I like the most : Binary tree is one of the simple form of Graphs!
If you don't know what Graphs are... no worries! I will be soon after this, going to post all necessary codes and details related to graphs.
Here you go for Basic implementation of Graphs!
#include<iostream>
using namespace std;
class node{
public:
int data;
node* left;
node* right;
node(int d){
this -> data = d;
this -> left = NULL;
this -> right = NULL;
}
};
node* buildTree(node* root){
cout<<"Enter the data: "<<endl;
int data;
cin>>data;
root = new node(data);
if(data == -1) return NULL;
cout<<"Enter the data for the left of "<<data<<endl;
root -> left = buildTree(root -> left);
cout<<"Enter the data for the right of "<<data<<endl;
root -> right = buildTree(root -> right);
return root;
}
int main()
{
node* root = NULL;
root = buildTree(root);
return 0;
}
💫🫡
Articles
9 articles in total
Recursion it is : LeetCode 494
read article
Chat GPT === hell ?
read article
How to Take Care of Your JavaScript Code Structure
read article
Best Hackathon Project 2024-25 ⚙️
read article
InOrder Traversal
read article
Binary Tree Implementation
currently reading
Are you ready for PYTHON?
read article
Beginners JavaScript
read article
DSA REPO!
read article
Featured ones: