Program of Binary Search Tree in C Language

preview_player
Показать описание
Audio may be interrupted in between. Please ask if anything is not understood.
Рекомендации по теме
Комментарии
Автор

it's just that u mix indian lang with eng, and I don't understand the indian lang part

Gupatik
Автор

thank you, but head ko global kyun nahi kiya?

situnandananda
Автор

Can someone help me out with this " struct BSTnode* create (struct BSTnode* head, int data) " what does it indicate?

NalbandAbhinay-E
Автор

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
int data;
struct node* left;
struct node* right;
};

struct node* newnode(struct node* head, int x){
if(head==NULL){
head=(struct node* )malloc(sizeof(struct node));
head->data=x;
head->left=NULL;
head->right=NULL;
}
return head;
}

struct node* create_bst(struct node* head, int x){
if(head==NULL){
head= newnode(head, x);
return head;
}

else if(x<=head->data){
head->left=create_bst(head->left, x);
}
else{
head->right=create_bst(head->right, x);
}
return head;
}

void inorder(struct node* head){
if(head!=NULL){

inorder(head->left);
printf("%d\t", head->data);
inorder(head->right);
}

}

int main(){
struct node* head=NULL;
printf("sample input: ");
int x, n=7;
while(n--){
scanf("%d", &x);
head=create_bst(head, x);
}
printf("sample output: ");
inorder(head);

return 0;
}

gunjansaxena
welcome to shbcf.ru