代码之家  ›  专栏  ›  技术社区  ›  Bokambo

编译错误:“Program.Node”不包含接受3个参数的构造函数

c#
  •  0
  • Bokambo  · 技术社区  · 6 年前

    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 回复  |  直到 6 年前
        1
  •  1
  •   Ulugbek Umirov    6 年前

    您需要将构造函数添加到 Node 类定义。

    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;
        }
    }