Incomplete n bst
Fri Sep 15 2023 06:27:24 GMT+0000 (Coordinated Universal Time)
Saved by
@Astik
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int num=1;
struct node{
int val;
struct node* left;
struct node* right;
};
void inorder(struct node* root){
if(root==NULL){
return;
}
inorder(root->left);
printf("%d -> ",root->val);
inorder(root->right);
}
struct node* createnode(int val){
struct node* nnode=(struct node*)malloc(sizeof(struct node));
nnode->val=val;
nnode->left=NULL;
nnode->right=NULL;
return nnode;
}
struct node* buildtree(struct node* node1,int val){
//node1=createnode(num);
if(num<=5){
node1->left=buildtree(node1->left,(node1->val)*2);
}
if(num<=5){
node1->right=buildtree(node1->right,(node1->val)*2 +1);
}
num++;
return node1;
}
int main(){
int n;
struct node* root=createnode(1);
clrscr();
printf("Enter n:- ");
scanf("%d",&n);
root=buildtree(root,n);
inorder(root);
getch();
return 0;
}
content_copyCOPY
Comments