Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct node
  5. {
  6. int data;
  7. struct node* left;
  8. struct node* right;
  9. };
  10. struct node* createNode(value){
  11. struct node* newNode = malloc(sizeof(struct node));
  12. newNode->data = value;
  13. newNode->left = NULL;
  14. newNode->right = NULL;
  15. return newNode;
  16. }
  17.  
  18.  
  19. struct node* insert(struct node* root, int data)
  20. {
  21. if (root == NULL) return createNode(data);
  22. if (data < root->data)
  23. root->left = insert(root->left, data);
  24. else if (data > root->data)
  25. root->right = insert(root->right, data);
  26.  
  27. return root;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement