Example #1
0
        //最小要素(root)を削除
        public Puzzle Pop()
        {
            Puzzle ret = root.val;

            root = Meld(root.l, root.r);
            Count--;
            return(ret);
        }
Example #2
0
 private SkewHeapNode CloneShallowSub(SkewHeapNode a)
 {
     if (a == null)
     {
         return(null);
     }
     return(new SkewHeapNode(CloneShallowSub(a.l), CloneShallowSub(a.r), a.val));
 }
Example #3
0
        //浅いクローン (node.val(Puzzle)の実体は複製せず参照値をコピー) (木の各ノードを複製する)
        public SkewHeap CloneShallow()
        {
            SkewHeapNode node = CloneShallowSub(root);
            SkewHeap     ret  = new SkewHeap();

            ret.root  = node;
            ret.Count = Count;
            return(ret);
        }
Example #4
0
 //2つのヒープをマージする (ここの実装が本質!)
 private SkewHeapNode Meld(SkewHeapNode a, SkewHeapNode b)
 {
     if (a == null)
     {
         return(b);
     }
     if (b == null)
     {
         return(a);
     }
     if (a.val.boardScore > b.val.boardScore)
     {
         Generic.Swap <SkewHeapNode>(ref a, ref b);
     }
     a.r = Meld(a.r, b);
     Generic.Swap <SkewHeapNode>(ref a.l, ref a.r);
     return(a);
 }
Example #5
0
        public Puzzle MaxValueSub(SkewHeapNode a)
        {
            if (a == null)
            {
                return(null);
            }

            Puzzle ret = MaxValueSub(a.l);
            Puzzle res = MaxValueSub(a.r);

            if (res != null && (ret == null || ret.boardScore < res.boardScore))
            {
                ret = res;
            }
            if (ret == null || ret.boardScore < a.val.boardScore)
            {
                ret = a.val;
            }
            return(ret);
        }
Example #6
0
 public SkewHeapNode(SkewHeapNode l, SkewHeapNode r, Puzzle puzzle)
 {
     this.l   = l;
     this.r   = r;
     this.val = puzzle;
 }
Example #7
0
 public SkewHeapNode(Puzzle puzzle)
 {
     val = puzzle;
     l   = null;
     r   = null;
 }
Example #8
0
 //要素xを追加
 public void Push(Puzzle x)
 {
     root = Meld(root, new SkewHeapNode(x));
     Count++;
 }
Example #9
0
 //空のヒープを作る
 public SkewHeap()
 {
     root  = null;
     Count = 0;
 }