#include <iostream>
using namespace std;
struct Node {
int val;
Node* left;
Node* right;
Node(int x) : val(x), left(nullptr), right(nullptr) {}
};
Node* insert(Node* root, int val) {
if (!root) return new Node(val);
if (val < root->val) root->left = insert(root->left, val);
else root->right = insert(root->right, val);
return root;
}
int findMin(Node* root) {
// Move left until no left child
while (root && root->left) {
root = root->left; // advance to left child
}
return root ? root->val : -1; // return value or -1 if empty
}
int main() {
Node* root = nullptr;
int values[] = {10, 5, 15, 2, 7, 1};
for (int v : values) {
root = insert(root, v);
}
int minVal = findMin(root);
cout << "Minimum element found: " << minVal << endl;
return 0;
}while (root && root->left) {
advance root to left child to find smaller values
move pointer left until no more left child
return root ? root->val : -1;
return smallest value found or -1 if tree empty