So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have
no matter where i call my function i get errors like unhandled exception at some memory.Code:/*function 3-takses as input the pointer to the root of the tree and returns a pointer to the node with the minimum value*/ CPPtr minimumvalue(CPPtr SP){ CPPtr min = NULL; //node of minimum value if(SP== NULL){ // if there is a node, begin comparing return NULL; } else{ if(SP->data<SP->left->data){ //if the node has smaller value than its left child min = SP; //update node of minimum value } else min = SP->left; //if the node has greater value than its left child //update node to the child if (min->data > SP->right->data){ //if the updated node has smaller value than right child min = SP->right; //update node } CPPtr minl = minimumvalue(SP->left); //check for left subtree // CPPtr minr = minimumvalue(SP->right); //check for right subtree return min; } }
anyone have idea on how to use recursion in this?