Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how would you do this?. Just need the concept. just few lines of codes to get me

ID: 3889362 • Letter: H

Question

how would you do this?. Just need the concept. just few lines of codes to get me started. and good explanation would be helpful.

4. inorder traversal: signature int BinaryTree: :inorderTraverse(int identity, int (*operation) (int, int)); This function performs an inorder traversal over the existing binary tree The first argument to the function is the identity element or the base case that can be used by the function (*operation) the second argument to start computation. eg. to multiply all the elements of the tree identity = 1 and *operation = multiply(int a, int b){return a * b; }

Explanation / Answer

Solution:

Inorder traversal traverses the nodes in a binary tree in this fashion

(Left, Vertex, Right).

This means that first go to the left node of a parent node then go to its left until there are no left children of that particular node and then mark that node as traversed then come back to the parent and go to the right and do the same.

Inorder traversal of a Binary search tree will give the nodes in a sorted order.

The code of Inorder function is given below,

void inorderTraversal(struct vertex* vertex)

{

     if (vertex== NULL)

          return;

inorderTraversal(vertex->left); // Go for the left child first as the algorithm says

     printf("%d ", vertex->data); //Displaying the data in the vertex

     inorderTraversal(vertex->right); // Go for the left child now

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)