Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. void f9(int * a, int n) {
  2.     int flag = 1;
  3.     while (flag) {
  4.         flag = 0;
  5.         int i;
  6.         for (i = n - 2; i >= 0; --i) {
  7.             int sgn1 = -1, sgn2 = -1;
  8.             if (a[i] == 0)
  9.                 sgn1 = 0;
  10.             if (a[i] < 0)
  11.                 sgn1 = 1;
  12.             if (a[i + 1] == 0)
  13.                 sgn2 = 0;
  14.             if (a[i + 1] < 0)
  15.                 sgn2 = 1;
  16.             if (sgn1 > sgn2) {
  17.                 int tmp = a[i];
  18.                 a[i] = a[i + 1];
  19.                 a[i + 1] = tmp;
  20.                 flag = 1;
  21.             }
  22.         }
  23.     }
  24. }
  25.  
  26. int f11(int * a, int n, int x) {
  27.     int l = -1, r = n;
  28.     while (l + 1 < r) {
  29.         int m = (l + r) / 2;
  30.         if (a[m] >= x)
  31.             r = m;
  32.         else
  33.             l = m;
  34.     }
  35.     return r;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement