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
| public void PutOddToLeft(int[] arr) { if (arr.Length <= 0) return; if (arr.Length == 1) return; int l = 0; int r = arr.Length - 1; int tmp; while(l < r) { while(arr[l] % 2 == 1 && l < r) { l++; } while (arr[r] % 2 == 0 && r > l) { r--; } if (l >= r) break; tmp = arr[l]; arr[l] = arr[r]; arr[r] = tmp; } }
|