Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Data structures 二叉树C中的级序插入#_Data Structures_Tree_Breadth First Search - Fatal编程技术网

Data structures 二叉树C中的级序插入#

Data structures 二叉树C中的级序插入#,data-structures,tree,breadth-first-search,Data Structures,Tree,Breadth First Search,假设我们得到一个数组[20,8,22,5,3,4,25,null,null,10,14,null,null,null,null],并且我们想从中使用级别顺序构造一个二叉树,我们如何在c#中做到这一点,因为它不允许null int 一个简单的伪代码: function create_node(index, arr) node n = node() if 2*index + 1 < arr.size and arr[2*index + 1] != null n.

假设我们得到一个数组[20,8,22,5,3,4,25,null,null,10,14,null,null,null,null],并且我们想从中使用级别顺序构造一个二叉树,我们如何在c#中做到这一点,因为它不允许null int

一个简单的伪代码:

function create_node(index, arr)
    node n = node()
    if 2*index + 1 < arr.size and arr[2*index + 1] != null
        n.left = create_node(2*index + 1, arr)
    if 2*index + 2 < arr.size and arr[2*index + 1] != null
        n.right = create_node(2*index + 2, arr)
函数创建_节点(索引、arr)
节点n=节点()
如果2*index+1

正如你所说,这里有空的问题。您可以简单地使用一些超出预期范围的值-可能是-1。

如果数组不能包含空值,那么如何为其中包含空值的数组指定空值?它必须是允许空值的类型:使用该类型。有趣的点。。java允许这样做。。。但是c#没有。所以,如果我们在java中使用它,我们可以进行插入。在c#中如何进行插入。我愿意修改数组来实现这一点。实际输入是什么?是文本文件吗?JSON格式?如上所述,您给出的数组表示法不是有效的C#语法,因此这就解决了问题。