SHARE
TWEET

Untitled

a guest Apr 24th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct SNode {
  5.     int data;
  6.     struct SNode* left;
  7.     struct SNode* right;
  8. } Node;
  9.  
  10. Node* newNode(int data);
  11. Node* insert(Node* node, int data);
  12.  
  13. Node* newNode(int data) {
  14.     Node* newNode = malloc(sizeof (Node));
  15.     newNode->data = data;
  16.     newNode->left = NULL;
  17.     newNode->right = NULL;
  18.     return newNode;
  19. }
  20.  
  21. Node* insert(Node* node, int data) {
  22.     if (node == NULL) {
  23.         return newNode(data);
  24.     }
  25.     if (data <= node->data) {
  26.         node->left = insert(node->left, data);
  27.     } else {
  28.         node->right = insert(node->right, data);
  29.     }
  30.     return node;
  31. }
  32.  
  33. int main(int argc, char *argv[]) {
  34.     Node* rootNode = newNode(123);
  35.     printf("Data: %i", rootNode->data);
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top