void inorder_call(struct node *root, int *arr, int *index) { if (root == NULL) return; inorder_call(root->left, arr, index); *(arr + *index) = root->data; (*index)++; inorder_call(root->right, arr, index); }
void inorder_call(node * root, int * arr, int * ptr){ /* 1. First Left subtree 2. Next visit data 3.Next Right subtree */ if (root == NULL) return; inorder_call(root->left, arr, ptr); arr[*ptr] = root->data; (*ptr)++;//must increament here only to retain value in next function call inorder_call(root->right, arr, ptr); }
void inorder(struct node *root, int *arr){ if (root == NULL || arr == NULL){ return; } int ptr = 0; inorder_call(root, arr, &ptr); }
void inorder(struct node *root, int *arr) { if (root == NULL || arr == NULL) return; int index = 0; inorder_call(root, arr, &index); }