Hi, i'm trying to write a function to find the rightmost leaf node (a node with no children).
This is the code I have so far.
in file tree.hCode:#include "tree.h"
void inorder(BTREE root);
int main()
{
return 0;
}
void inorder(BTREE root)
{
if (root != NULL)
{
inorder(root -> left);
printf("%c ", root -> d);
inorder(root -> right);
}
}
/*BTREE findRightMostLeaf(BTREE root)
{
if (root != NULL)
{
findRightMostLeaf(root -> right)
if()
}
}*/
void replaceWithRightmost(BTREE root)
{
root = findRightMostLeaf(root);
}
I can figure out how to solve this problem with a bunch of messy if statement/loop code, but I was looking for a recursive solution, similar to the function already defined in main.Code:#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
typedef char DATA;
struct node {
DATA d;
struct node *left;
struct node *right;
};
typedef struct node NODE;
typedef NODE *BTREE;
Recursion is my weakness. Thanks for any help.