(a, i, j, dire)
| 5 | # or DESCENDING; if (a[i] > a[j]) agrees with the direction, |
| 6 | # then a[i] and a[j] are interchanged.*/ |
| 7 | def compAndSwap(a, i, j, dire): |
| 8 | if (dire == 1 and a[i] > a[j]) or (dire == 0 and a[i] < a[j]): |
| 9 | a[i], a[j] = a[j], a[i] |
| 10 | |
| 11 | # It recursively sorts a bitonic sequence in ascending order, |
| 12 | |
| 13 | |
| 14 | # if dir = 1, and in descending order otherwise (means dir=0). |