コード例 #1
0
        private void AllocationTree(List <int> list, NTree nTree)
        {
            var avr   = list.Average();
            int index = 0;
            var num   = Math.Abs(list[0] - avr);

            for (int i = 0; i < list.Count; i++)
            {
                if (Math.Abs(list[i] - avr) < num)
                {
                    num   = Math.Abs(list[i] - avr);
                    index = i;
                }
            }

            nTree.value = BitConverter.GetBytes(list[index]);
            if (index > 0)
            {
                nTree.l = new NTree();
                AllocationTree(list.GetRange(0, index), nTree.l);
            }
            if (index < list.Count - 1)
            {
                nTree.r = new NTree();
                AllocationTree(list.GetRange(index + 1, list.Count - index - 1), nTree.r);
            }
        }
コード例 #2
0
 public void addRight(NTree left)
 {
     l = left;
 }
コード例 #3
0
 public void addLeft(NTree left)
 {
     l = left;
 }