0

I am writing a test program to test given binary tree is BST or not, but i am getting below errors:

Compilation error (line 33, col 13): 'Program.Node' does not contain a constructor that takes 3 arguments
Compilation error (line 34, col 13): 'Program.Node' does not contain a constructor that takes 3 arguments
Compilation error (line 35, col 13): 'Program.Node' does not contain a constructor that takes 3 arguments

using System;

public class Program
{
    public  class Node
    {
        public int value;
        public Node left;
        public Node right;      
    }



     public static bool IsValidBST(Node root) {
        return IsValid (root, int.MinValue, int.MaxValue);

    }

    private static bool IsValid (Node node, int Min, int Max)
    {
        if (node == null)
            return true;

        if((node.value > Min && node.value < Max) && IsValid (node.left , Min, node.value) && IsValid(node.right, node.value, Max))
            return true;
        else
            return false;
    }

    public static void Main()
    {
        Node n1 = new Node(1,null,null);
        Node n3 = new Node(3,null,null);
        Node n2 = new Node(2, n1, n3);
        Console.WriteLine(IsValidBST(n2));
        Console.ReadLine();

    }
}
1

1 Answer 1

1

You need to add constructor to Node class definition.

public class Node
{
    public int value;
    public Node left;
    public Node right;

    public Node(int value, Node left, Node right)
    {
        this.value = value;
        this.left = left;
        this.right = right;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.