CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C++

Сортировка бинарной вставкой

1120 Views
Copy Code Show/Hide Line Numbers
   1:  void past_sort_bin(mat r[], int N)
   2:  {
   3:      int i, left, right, k, s;
   4:      mat x;
   5:   
   6:      for (i = 1; i < N; i++)
   7:      {
   8:          left = 0;
   9:          right = i;
  10:   
  11:          k = (right + left)/2;
  12:   
  13:          while (left != k)
  14:          {
  15:              if (r[k].code > r[i].code)
  16:                  right = k;
  17:              else
  18:                  left = k;
  19:              k = (right + left)/2;
  20:          }
  21:   
  22:          if (r[left].code < r[i].code)
  23:          {
  24:              if (r[i].code > r[k].code)
  25:                  left = k+1;
  26:              else
  27:                  left = k;
  28:          }
  29:   
  30:          x = r[i];
  31:   
  32:          for (s = i; s > left; s--)
  33:              r[s] = r[s-1];
  34:   
  35:          r[left] = x;
  36:      }
  37:  }
by Amberize
  April 18, 2010 @ 6:54am

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate