Guest User

Untitled

a guest
Jan 23rd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. struct node_el{
  4. struct node *left_child;
  5. struct node *right_child;
  6. struct node *root;
  7. int index;
  8. };
  9. typedef struct node_el node;
  10.  
  11.  
  12. int spurt_hole(node *start){
  13. if (start->left_child != NULL && start->right_child !=NULL){
  14. printf("index %d has children on right and left\n", start->index);
  15. spurt_hole(start->left_child);
  16. spurt_hole(start->right_child);
  17. }
  18. else{
  19. if (start->left_child != NULL){
  20. printf ("index %d left but not right\n", start->index);
  21. spurt_hole(start->left_child);
  22. return;
  23. }
  24. if (start->right_child !=NULL){
  25. printf("index %d right but not left\n", start->index);
  26. spurt_hole(start->right_child);
  27. return;
  28. }
  29. printf("index %d has neither children\n", start->index);
  30. return;
  31. }
  32. return;
  33.  
  34.  
  35. }
  36.  
  37. int initialize_node(node *sample, node *rooter){
  38. sample->left_child = NULL;
  39. sample->right_child = NULL;
  40. sample->index = 0;
  41. sample->root= rooter;
  42. }
  43.  
  44.  
  45. void main() {
  46. int i;
  47. node *rooter;
  48. node *temp1;
  49. node *temp2;
  50. node *root_ptr;
  51.  
  52. rooter = (node *)malloc(sizeof(node));
  53.  
  54. root_ptr = rooter;
  55. printf("initializing unbalanced tree");
  56.  
  57. for (i=0; i<20; i++){
  58.  
  59. printf("%d\n",i);
  60.  
  61. temp1 = (node *) malloc(sizeof(node));
  62. temp2 = (node *) malloc(sizeof(node));
  63.  
  64. initialize_node(temp1,rooter);
  65. initialize_node(temp2,rooter);
  66.  
  67.  
  68. temp1->index = i;
  69. temp2->index = 22;
  70.  
  71. rooter->left_child = temp1;
  72. rooter->right_child = temp2;
  73. rooter = temp1;
  74. }
  75. spurt_hole(root_ptr);
  76.  
  77. }
Add Comment
Please, Sign In to add comment