Minimum Value of a Binary Search Tree

Question:Write a C program to find the minimum value in a binary search tree.

Solution:
#include<stdio.h>
struct binarysearchtree
{
int data;
struct binarysearchtree* left;
struct binarysearchtree* right;
};
typedef struct binarysearchtree* tree;

tree min(tree T)
{
if (T==NULL)
return NULL;
else
{
if(T->left==NULL)
return T;
else
return min(T->left);
}
}


Click Here For More Questions

1 comment:

  1. I see a simpler solution here. Use iteration to find the lowest tree point.

    int minTree(tree t){
    while (t.left != null)
    t = t.left;
    return t.data;
    }

    ReplyDelete