black_friday/Assets/Scripts/PriorityQueue.cs
/// <summary>
/// Enqueues an object of type T into the priority queue
/// </summary>
/// <param name="data">The object to add</param>
Enqueues an object of type T into the priority queue
Enqueues an object of type T into the priority queue
public void Enqueue(T data)
        {
            innerHeap.Add(data);
            int index = innerHeap.Count - 1;
            while (index > 0)
            {
                int parentIndex = ((index & 1) == 1) ? index - 1 : index - 2;
                parentIndex >>= 1;
                if (innerHeap[parentIndex].CompareTo(innerHeap[index]) > 0)
                {
                    SwapFromIndices(parentIndex, index);
                }
                index = parentIndex;
            }
        }
public void Enqueue ( T data ) { innerHeap . Add ( data ) ; int index = innerHeap . Count - 1 ; while ( index > 0 ) { int parentIndex = ( ( index & 1 ) == 1 ) ? index - 1 : index - 2 ; parentIndex >>= 1 ; if ( innerHeap [ parentIndex ] . CompareTo ( innerHeap [ index ] ) > 0 ) { SwapFromIndices ( parentIndex , index ) ; } index = parentIndex ; } }
Enqueues an object of type T into the priority queue
Enqueues an object of type T into the priority queue
//Add data to heap //Get the parent's index by checking if even or odd, then subtracting 1 or 2 respectively //And lastly dividing by 2 //Is parent's data larger than childs? If soswap
data
T
The object to add
The object to add