title: Merge Sort Repeating the Same Numbers
body: <p>I'm trying to rebrush up on my basic CS skills and trying to implement a simple merge sort algorithm. I can't figure out what I did wrong but the code is just saving the same numbers repeatedly. This is the output I get:</p>
  
  <p><a href="https://i.stack.imgur.com/9L5u2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9L5u2.png" alt="enter image description here"></a></p>
  
  <p>I was using this site as a guide: <a href="http://geeksquiz.com/merge-sort/" rel="nofollow noreferrer">http://geeksquiz.com/merge-sort/</a> which I confirmed does actually work properly (with a slight modification.) Anyone mind sharing any obvious bugs in my code that I couldn't catch?</p>
  
  <pre><code>void Merge(int arr[], int left, int right, int pivot)
  {
  
      int leftCount = pivot - left + 1;
      int rightCount = right - pivot;
  
      int *leftSec = new int[leftCount];
      int *rightSec = new int[rightCount];
  
      for (int i = 0; i &lt; leftCount; i++)
      {
          leftSec[i] = arr[left + i];
      }
      for (int j = 0; j &lt; rightCount; j++)
      {
          rightSec[j] = arr[pivot + 1 + j];
      }
  
      int i = 0;
      int j = 0;
      int k = leftCount;
      while(i &lt; leftCount &amp;&amp; j &lt; rightCount)
      {
          if (leftSec[i] &lt;= leftSec[j])
          {
              arr[k] = leftSec[i];
              i++;
          }
          else
          {
              arr[k] = rightSec[j];
              j++;
          }
          k++;
      }
      while (i &lt; leftCount)
      {
          arr[k] = leftSec[i];
          i++;
          k++;
      }
      while (j &lt; rightCount)
      {
          arr[k] = rightSec[j];
          j++;
          k++;
      }
      delete[] leftSec;
      delete[] rightSec;
  }
  
  void MergeSort(int arr[], int left, int right)
  {
      if (left &lt; right)
      {
          int pivot = (left + right) / 2;
          MergeSort(arr, left, pivot);
          MergeSort(arr, pivot + 1, right);
          Merge(arr, left, right, pivot);
      }
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      int t;
      int unsortedArray[] = { 94, 384, 934, 3, 56, 57, 94, 60, 90 };
      int arrayLength = sizeof(unsortedArray) / sizeof(int);
      printArray(unsortedArray, arrayLength);
      MergeSort(unsortedArray, 0, arrayLength);
      printArray(unsortedArray, arrayLength);
      cin &gt;&gt; t;
      return 0;
  }
  </code></pre>