Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
#include<stdio.h>
#include<stdlib.h>
struct node{
int val;
struct node* left;
struct node* right;
};
typedef struct node* Tree;
void insert(Tree *root,int x){
if (*root==NULL){
*root = (struct node*)malloc(sizeof(struct node));
(*root)->val=x;
(*root)->left=(*root)->right=NULL;
return;
}
if (x<(*root)->val) *root=(*root)->left;
else if (x>(*root)->val) *root=(*root)->right;
}
void inorder(Tree root){
if (root==NULL) return;
inorder(root->left);
printf("%d ",root->val);
inorder(root->right);
}
int main(){
Tree root=NULL;
insert(&root,10);
insert(&root,5);
insert(&root,1);
insert(&root,12);
inorder(root);
getchar();
return 0;
}
#include<stdio.h>
#include<stdlib.h>
struct node{
int val;
struct node* left;
struct node* right;
};
typedef struct node* Tree;
void insert(Tree *root,int x){
if (*root==NULL){
*root = (struct node*)malloc(sizeof(struct node));
(*root)->val=x;
(*root)->left=(*root)->right=NULL;
return;
}
if (x<(*root)->val) insert(&(*root)->left, x);
else if (x>(*root)->val) insert(&(*root)->right, x);
}
void inorder(Tree root){
if (root==NULL) return;
inorder(root->left);
printf("%d ",root->val);
inorder(root->right);
}
int main(){
Tree root=NULL;
insert(&root,10);
insert(&root,5);
insert(&root,1);
insert(&root,12);
inorder(root);
getchar();
return 0;
}
But on your next insert(&root,5), I do not see where you are setting val=x or setting the left/right ptrs.
Also, if you had a tree, say of depth 5, and if you tried to insert a value, x, which should land, say at depth 5 or 6, then I am not sure I am seeing the traversal down the tree to get to the proper node.