コード例 #1
0
        private void HeapifyUp(int position)
        {
            int value = data[position].Priority;
            int pos   = position;

            while (pos != 0 || value > data[FatherPos(pos)].Priority)
            {
                HeapItem <T> temp = data[position];
                data[position]       = data[FatherPos(pos)];
                data[FatherPos(pos)] = temp;

                pos   = FatherPos(pos);
                value = data[position].Priority;
            }
        }
コード例 #2
0
        public void EnQueue(T item, int priority)
        {
            if (HeapType == HeapType.MinHeap)
            {
                priority = -priority;
            }

            if (Count >= Capacity)                      //DUPLICANDO LA CAPACIDAD
            {
                var temp = (HeapItem <T>[])data.Clone();
                data = new HeapItem <T> [data.Length * 2];
                Array.Copy(temp, data, temp.Length);
            }

            data[Count++] = new HeapItem <T>(item, priority);
            HeapifyUp(Count - 1);
        }