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; } }
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); }