Esempio n. 1
0
        public void Insert(NodeHeap <T> n)//MAKE PRIVATE.
        {
            Int32        i;
            NodeHeap <T> temp;

            if (_last >= _capacity - 1)
            {
                __Copy();
                //Console.WriteLine("Queue is filled");
                //return;
            }
            this._last        = this._last + 1;
            n.Idx             = _last;
            _cellspace[_last] = n;
            i = _last;

            while (i > 1 && (_p(_cellspace[i].Value) < _p(_cellspace[i / 2].Value)))
            {
                //Move n up
                temp                  = _cellspace[i];
                _cellspace[i]         = _cellspace[i / 2];
                _cellspace[i].Idx     = i;
                _cellspace[i / 2]     = temp;
                _cellspace[i / 2].Idx = i / 2;
                i = i / 2;
            }
            _count = _count + 1;
            __ComputeH();
        }
Esempio n. 2
0
        public void Add(T item)
        {
            NodeHeap <T> n = new NodeHeap <T>();

            n.Value = item;
            Insert(n);
        }
Esempio n. 3
0
 private void __Copy()
 {
     NodeHeap <T>[] nb = new NodeHeap <T> [_capacity * 2];
     this._capacity *= 2;
     for (Int32 i = 0; i < _cellspace.Length; i++)
     {
         nb[i] = _cellspace[i];
     }
     _cellspace = nb;
 }
Esempio n. 4
0
        public Node <T> RightSibling(Node <T> node)
        {
            NodeHeap <T> np = node as NodeHeap <T>;

            if (np == null || np.Idx == 1 || np.Idx + 1 > _last)
            {
                return(null);
            }
            return(_cellspace[np.Idx + 1]);
        }
Esempio n. 5
0
        public Node <T> LeftMostChild(Node <T> node)
        {
            NodeHeap <T> np = node as NodeHeap <T>;

            if (np == null || np.Idx * 2 > _last)
            {
                return(null);
            }
            return(_cellspace[np.Idx * 2]);
        }
Esempio n. 6
0
        public Node <T> Parent(Node <T> node)
        {
            NodeHeap <T> np = node as NodeHeap <T>;

            if (np == null || np.Idx == 1)
            {
                return(null);
            }
            return(_cellspace[np.Idx / 2]);
        }