daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Node{
  5.   double nodeValue;
  6.   struct Node *parent;
  7.   struct Node *left;
  8.   struct Node *right;
  9. };
  10.  
  11.  
  12. struct Node *createNode(struct Node *pa, int n){
  13.   if(n==0){
  14.     return NULL;
  15.   }else{
  16.     struct Node *newNode = (struct Node*) malloc(sizeof(struct Node));
  17.     int div=(n-1)%2;
  18.     if(div==1){
  19.       newNode->left = createNode(newNode, (n-1)/2+1);
  20.       newNode->right = createNode(newNode, (n-1)/2);
  21.     }else{
  22.       newNode->left = createNode(newNode, (n-1)/2);
  23.       newNode->right = createNode(newNode, (n-1)/2);
  24.     }
  25.     newNode->parent = pa;
  26.     newNode->nodeValue =((double)rand()) / RAND_MAX;
  27.     printf("NewNode: %f\n", newNode->nodeValue);
  28.     return newNode;
  29.   }
  30. }
  31.  
  32. struct Node *makeRandomTree(int numberOfNodes){
  33.   return createNode(NULL,numberOfNodes);
  34. }
  35.  
  36. int main(){
  37.   makeRandomTree(5);
  38.   return 0;
  39. }
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
 
Top