Hello!

I need some help with writing a binary tree class. There are two methods that I have no idea how to approach:
1) Finding the left-most leaf.
Example:
...............A............
............../.\...........
.............B...C...........
............/..../\..........
...........D....E..F........
.............../..............
..............G..............
............./..............
............H..............
.........../..............
..........I..............

In this case, "I" would be the left-most leaf. Now, I have to write a method that returns a pointer to it.
My guess is that it would involve recursion in some way (basically, going down all the possible paths) and a static variable that would increase by 1 if it goes down a left path and decrease by one if it goes down a right path. Therefore, the path on which the variable gets the largest value is the path to the left leaf. But I dunno how to right this down in code. Besides, I dunno if it'll help in some way to return the pointer to the left-most leaf.
2) Deleting the left-most leaf. This, I have no idea how to do at all.

Please post your binary tree implementation so we could discuss more on searching based on the code.

Well, all I have is this:

``````template <class T>
class Node
{
T data;
Node *left, *right;

Node (T i, Node<T> *l, Node<T> *r)
{
data = i;
left = l;
right = r;
}

friend class BinaryTree<T>;
};

template <class T>
class BinaryTree
{
Node *root;
public:
//destructor and default constructors will go here
};``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.