在我的'Program.cs'中,我试图从另一个类'BinTree.cs'调用方法'inOrder()'。
类BinTree以class BinTree<T> where T : IComparable
我试过了:
inOrder();
和
BinTree<T>.inOrder();
和
BinTree<int>.inOrder();
但这些都不起作用。
感谢您的光临。
编辑:
class Program
{
static void Main(string[] args)
{
Node<int> tree = new Node<int>(6);
tree.Left = new Node<int>(2);
tree.Left.Right = new Node<int>(5);
tree.Left.Right.Data = 3;
tree.Right = new Node<int>(8);
(new BinTree<int>()).inOrder();
}
EDIT2:
private Node<T> root;
public BinTree() //creates an empty tree
{
root = null;
}
public BinTree(Node<T> node) //creates a tree with node as the root
{
root = node;
}
答案 0 :(得分:0)
据我所知,您需要创建一个BinTree<int>
实例并在构造函数中传入Node<int>
实例。像这样:
class Program
{
static void Main(string[] args)
{
// Create Node instances for tree
Node<int> node = new Node<int>(6);
node.Left = new Node<int>(2);
node.Left.Right = new Node<int>(5);
node.Left.Right.Data = 3;
node.Right = new Node<int>(8);
// Create tree, set root node
BinTree<int> tree = new BinTree<int>(node);
tree.inOrder(); // Call inOrder method of tree instance
}
}