Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1.         void merge(int[] array, int left, int mid, int right)
  2.         {
  3.             int i;
  4.             int left_counter = 0;
  5.             int right_counter = mid + 1;
  6.             int[] sorted = new int[10];
  7.  
  8.             for (i = 0; i <= right; i++)
  9.             {
  10.                 if ((left_counter <= mid) && (right_counter <= right))
  11.                 {
  12.                     if (array[left_counter] < array[right_counter])
  13.                     {
  14.                         sorted[i] = array[left_counter];
  15.                         left_counter++;
  16.                     }
  17.                     else {
  18.                         sorted[i] = array[right_counter];
  19.                         right_counter++;
  20.                     }
  21.                 }
  22.                 if (left_counter > mid)
  23.                 {
  24.                     sorted[i] = array[right_counter];
  25.                     right_counter++;
  26.                 }
  27.                 if (right_counter > right)
  28.                 {
  29.                     sorted[i] = array[left_counter];
  30.                     left_counter++;
  31.                 }
  32.             }
  33.  
  34.             for (i = 0; i <= right; i++)
  35.             {
  36.                 array[i] = sorted[i];
  37.             }
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement