Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. void binaryinsertionsort(int *arr, int n)
  2. {
  3. int b;
  4. int c;
  5. int e;
  6. int i;
  7. int j;
  8. int k;
  9. double tmp;
  10.  
  11. for(i = 2; i <= n; i++)
  12. {
  13. b = 1;
  14. e = i-1;
  15. c = (b+e)/2;
  16. while(b!=c)
  17. {
  18. if( arr(c-1)>arr(i-1) )
  19. {
  20. e = c;
  21. }
  22. else
  23. {
  24. b = c;
  25. }
  26. c = (b+e)/2;
  27. }
  28. if( arr(b-1)<arr(i-1) )
  29. {
  30. if( arr(i-1)>arr(e-1) )
  31. {
  32. b = e+1;
  33. }
  34. else
  35. {
  36. b = e;
  37. }
  38. }
  39. k = i;
  40. tmp = arr(i-1);
  41. while(k>b)
  42. {
  43. arr(k-1) = arr(k-1-1);
  44. k = k-1;
  45. }
  46. arr(b-1) = tmp;
  47. }
  48. }
Add Comment
Please, Sign In to add comment