fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5.  
  6. #define MAX_B 7
  7.  
  8. typedef struct _ramo{
  9. int nbanane;
  10. struct _ramo *dx;
  11. struct _ramo *sx;
  12. }ramo;
  13.  
  14.  
  15. ramo * creaAlbero(int n){
  16. printf("%d\n",n);
  17.  
  18. ramo *root = malloc(sizeof(ramo));
  19. root->nbanane=rand()%MAX_B;
  20. printf("BANANA! %d\n",root->nbanane);
  21. root->dx=NULL;
  22. root->sx=NULL;
  23.  
  24. if ((int)(rand()%n)==0)
  25. root->dx = creaAlbero(n+1);
  26. if ((int)(rand()%n)==0)
  27. root->sx = creaAlbero(n+1);
  28.  
  29. return root;
  30. }
  31.  
  32. int main(){
  33. srand((unsigned int)time(NULL));
  34. ramo *root=NULL;
  35. root = creaAlbero(1);
  36. if (root==NULL) {
  37. printf("EMPTY!!");
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 2184KB
stdin
Standard input is empty
stdout
1
BANANA! 4
2
BANANA! 6
2
BANANA! 6
3
BANANA! 5
3
BANANA! 2
4
BANANA! 6