Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
11
#include<stdio.h> #include<stdlib.h> typedef struct { struct node *lchild,*rchild; int info; }node; node *insert(node *root,int a) { node *ptr,*par,*temp; temp=(node*)malloc(sizeof(node)); temp->info=a; temp->rchild=NULL; temp->lchild=NULL; ptr=root; par=NULL; while(ptr!=NULL) { par=ptr; if(ptr->info<a) ptr=ptr->rchild; else if(ptr->info>a) ptr=ptr->lchild; else{ printf("its a duplicate"); return root;} } if(par==NULL) root=temp; else if(par->info<a) par->rchild=temp; else par->lchild=temp; printf("%d b\n", root->info); return root; } void preo(node* root) { node *ptr=root; if(root==NULL) return; printf("%d",ptr->info); preo(root->lchild); preo(root->rchild); } void poo(node* root) { node *ptr=root; if(root==NULL) return; poo(root->lchild); poo(root->rchild); printf("%d",ptr->info); } void ino(node* root) { node *ptr=root; if(root==NULL) return; ino(root->lchild); printf("%d",ptr->info); ino(root->rchild); } struct node * search(node* root,int number) { if (root == NULL ) return NULL; if (number == root->info ) return root->info; if( number < root->info ) return search(root->lchild,number); if (number > root->info ) return search(root->rchild,number); } int main() { int a,b,c; node *root=NULL; printf("enter the no of elements to be entered in a tree :"); scanf("%d",&a); for(int i=0;i<a;i++) { scanf("%d",&b); //"%d",root->info); root=insert(root,b); } preo(root); printf("\n"); ino(root); printf("\n"); poo(root); root=search(root,5); if(root==NULL) printf("not found"); else printf("dound"); }
run
|
edit
|
history
|
help
0
recurs fibo1
a3
ATM
Building squares using smallest amount of matches
edmond@DESKTOP-M2BC2LH
Ultimo avance de pregunta 1 guía4
Maximum of Arrays
CstructProduct
Square pyramid
B_141202_CADENA_NUMERO