Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. private static bool Dswap(int[] a, int i, int j, int d) {
  2. bool r = false;
  3.  
  4. if (i == j) return true;
  5.  
  6. if (a[i] >= j - d && a[i] <= j + d &&
  7. a[j] >= i - d && a[j] <= i + d) {
  8. r = true;
  9. int t = a[i];
  10. a[i] = a[j];
  11. a[j] = t;
  12.  
  13. if (a[i] == i) throw new Exception("Was here!");
  14. if (a[j] == j) throw new Exception("Was here!");
  15. }
  16.  
  17. return r;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement