title: Better way to implement or feedback on this C# Max Heap Priority Queue
body: <p>been writing some data structures of late as a review for myself. I was wondering if anyone had some feedback on the code below, better, faster ways perhaps?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  namespace MaxHeapPriorityQueue
  {
      public class PriorityItem&lt;T&gt;
      {
          public T Data { get; set; }
          public int Priority { get; set; }
          public PriorityItem(T data, int priority)
          {
              Data = data;
              Priority = priority;
          }
  
          public string ToString()
          {
              return Priority.ToString();
          }
      }
  
      public class PriorityQueue&lt;T&gt;
      {
          private List&lt;PriorityItem&lt;T&gt;&gt; array;
          public PriorityQueue()
          {
              array = new List&lt;PriorityItem&lt;T&gt;&gt;();
          }
  
          public void enqueue(T data, int priority)
          {
              PriorityItem&lt;T&gt; item = new PriorityItem&lt;T&gt;(data, priority);
              array.Add(item);
              MaxHeapify();
          }
  
          public T dequeue()
          {
              T max = array[0].Data;
              array.RemoveAt(0);
              MaxHeapify();
              return max;
          }
  
          public void MaxHeapify()
          { 
              //children must be less than the parent
              //left = 2i-1
              //right = 2i
              for (int i = 0; i &lt; array.Count; i++)
              { 
                  int leftPos = CalcLeft(i);
                  int rightPos = CalcRight(i);
                  int leftPriority = 0;
                  int rightPriority = 0;
  
                  if (leftPos !=-1)
                      leftPriority = array[leftPos].Priority;
  
                  if (rightPos !=-1)
                      rightPriority = array[rightPos].Priority;
  
                  //swap with parents where applicable
                  int highestPriority = 0;
                  if (leftPriority &gt; array[i].Priority)
                  {
                      highestPriority = leftPriority;
                  }
                  else
                  if (rightPriority &gt; array[i].Priority &amp;&amp; rightPriority &gt; leftPriority)
                  {
                      highestPriority = rightPriority;
                  }
  
                  //swap 
                  PriorityItem&lt;T&gt; temp;
                  temp = array[i];
                  if (highestPriority == leftPriority &amp;&amp; leftPos != -1)
                  {                    
                      array[i] = array[leftPos];
                      array[leftPos] = temp;
                  }
                  else if (highestPriority == rightPriority &amp;&amp; rightPos!=-1)
                  {
                      array[i] = array[rightPos];
                      array[rightPos] = temp;
                  }
              }
  
          }
  
          int CalcLeft(int i)
          {
              i++;
              if ((2 * i)-1 &lt; array.Count)
                  return (2 * i) -1;
              else
                  return -1;
          }
  
          int CalcRight(int i)
          {
              i++;
              if ((2 * i)  &lt; array.Count)
              {
                  return (2 * i);
              }
              else
              {
                  return -1;
              }
          }
  
      }
  
  
      class Program
      {
          static void Main(string[] args)
          {
              PriorityQueue&lt;string&gt; pq = new PriorityQueue&lt;string&gt;();
  
              pq.enqueue("a", 1);
              pq.enqueue("b", 2);
              pq.enqueue("c", 4);
              pq.enqueue("e", 5);
              pq.enqueue("d", 3);
  
              string val = pq.dequeue();
              Assert.AreEqual("e", val);
              val = pq.dequeue();
              Assert.AreEqual("c", val);
              val = pq.dequeue();
              Assert.AreEqual("d", val);
  
              pq.enqueue("e", 10);
  
              val = pq.dequeue();
              Assert.AreEqual("e", val);
              val = pq.dequeue();
              Assert.AreEqual("b", val);
              val = pq.dequeue();
              Assert.AreEqual("a", val);
  
          }
      }
  }
  </code></pre>