is it about sorting?

Hello,
I need your help, Ive got a function and I consider it as a sort function but I am not sure about the type of sort and the complexity.
Moreover I cannot quite get what does exactly the "||" mean in the specific point of that function.
Thank you for any help

the function is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

void teest(int *prm1, int prm2)
{
  int m, n, x, y, z, tmp, flg;
  for(m=prm2-1; m>0; --m)
  {
    flg = 0;
    x = y = n = 0;
    z = 1;

    for (; n<m; x++, z++)
    {
      if (*(int*)(prm1+n) > *(int*)(prm1+z))
      {
        x = y + *prm1 - *(prm1+n+1);
        tmp = *(prm1+n);
        *(prm1+n) = *(prm1+n+1);
        y = x?++x:x-2;
        *(prm1+n+1) = tmp;
        flg=1;
        if (x > y)
          y = tmp+x || tmp == ++x;
      }
      ++n;
    }

    if (!flg)
      break;
  }
}
|| is logical Inclusive OR.

*(int*)(prm1+n) can be written as prm1[n] (the cast is unnecessary)
*prm1 can be written as prm1[0] and similarly,
*(prm1+n+1) can be written as prm1[n + 1]

To evaluate y = tmp+x || tmp == ++x;, you'll need to know the order of operator precedence.
http://en.cppreference.com/w/cpp/language/operator_precedence

Is this code deliberately obscure?
Last edited on
Is this code deliberately obscure?


Looks like it.

|| here is being used to short circuit. IE: the right hand of the || operator is only explored/evaluated if the left hand side is false.


EDIT -- I actually had incorrect example code here so I removed it to avoid confusion.
Last edited on
n<m and flg screams bubble sort. I'd recommend unobfuscating the code step by step to make sure.

thanks guys :)
Last edited on
Topic archived. No new replies allowed.