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 indicated



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) T/Utility function to create a new tree node 12. { Node* temp = new Node; 13. temp->data = data; 14. temp->left = temp->right = NULL; return temp; 16.) 15. struct Node* search(int data) struct Node "current - binaryRoot; printf(" Visiting elements: "); 17 18 19 20. 21. 22. 32 23 24 25. 26. 27 30 28. 29 while (current->data 1 - data & currentI-NULL) if (current != NULL) printf("%d", current->data); 47. //go to left tree if (current->data > data) { current = current->left; } //else go to right tree 30. else { 31 current = current->right; 32. } 33. 34. /ot found 35. if (current == NULL) { 36. return NULL; 37. } 38. } 39. return current; 40.) 41. 42. void insertBinary(int data) 43. { 44. Node *temp = binaryRoot, *prev = NULL; 45. if (temp == NULL) temp = newNode(data); 46. else { while (temp != NULL) 48. { prev = temp; 49. if (temp->data == data) { printf(" This data exist in break; } 50. 51. if (temp->data right; 52. else if (temp->data > data) temp = temp->left; 53. } 54. 55. if (prev->data > data) prev->left = newNode(data); 56. else prev->right = newNode(data); } 58. } 59. 60. 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 */ (D) 57. 77. 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
