Question: 3. Given the main part and global declarations below complete the code of the preorder(), inorder() and postorder( ) searches by filling the empty spaces



3. Given the main part and global declarations below complete the code of the preorder(), inorder() and postorder( ) searches by filling the empty spaces indicated with A to I. 4. struct Node { 5. int data; 6. struct Node *left, right; 7. }; 8. 9. struct Node* root, "binaryRoot = NULL; 10. 11. Node* newNode(int data) 7/Utility function to create a new tree node 12. { Node* temp = new Nodey 13. temp->data = data; 14. temp->left temp->right NULL; 25. return temp: 16.) 20 12 struct Node searchintata struct Node current - binary 19 printf(" visiting elements: 21 while (current->data tdita corrent-ULL) 22 1 (current = NULL) 23. printf("%d"current-data) 24 25 1/8 to left tree 26 if (current->data > data) { 27 current -current->left 28. 3 29. Welse go to right tree 38. else { 31 current current-right) 32 3 33. 34. V not found 35. if (current -- NULL) 36. return NULL; 37. } 38 3 39 return current; 48.) 41. 42. void insertBinary(int dota) 43. 44. Node *temp = binaryRoot, "prev = NULL; 45. if (temp = NULL) temp = newNode(data); 46. else 47 { while (temp != NULL) 48. { prev - temp; 17 (tenp->data - data) { printf(" This data exist in 49. break) 50. 51. if (temp->data right: 52 else 1f (temp->data > data) temp = temp->left; 53. } 54. if (prev->data > data) prev->left = newNode(data); 56. else prev-Sright = new Node (data) 57 58.) 55 59. 6e. void printPostorder(struct Node* node) 61. { if (node == NULL) return; 62. 63. // first recur on left subtree 64. (A) 65. 66. // then recur on right subtree 67. .(B) 68. 69. // now deal with the node 70. (C 71. ) 72 73. void print Inorder(struct Node* node) 74. if (node NULL) return; 75. 76. /* first recur on left child */ 77. (D) 78. 79. /* then print the data of node */ 80. .....(E) 81. 82. /* now recur on right child */ 83. ...(F)} 84. 85. void printPreorder(struct Node* node) 86. {if (node == NULL) return; 87. 88. /* first print data of node */ 89. .....(G) 90. /* then recur on left subtree */ 91. ... (H) 92. 93. /* now recur on right subtree */ 94. ....(I) 95. }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
