-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderArray14.java
More file actions
40 lines (38 loc) · 1.19 KB
/
OrderArray14.java
File metadata and controls
40 lines (38 loc) · 1.19 KB
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
32
33
34
35
36
37
38
39
40
package offer;
/*
* ��������˳��ʹ����λ��ż��ǰ��
*/
public class OrderArray14 {
public void reOrderArray(int [] array) {
for (int i = 0; i < array.length; i++) {
int end = 0;
if(array[i] % 2 ==0) {
int j = 0;
for (j = i + 1; j < array.length; j++) {
if(array[j] % 2 == 0){
//��һ��ż����滹��ż��
}else{
int swap = array[j];
end = j;
while(j > i){
array[j] = array[j - 1];
j--;
}
array[i] = swap;
break;
}
}
if(end == array.length){
break;
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]);
}
}
public static void main(String[] args) {
int[] array = {1,2,3,4,5,6,7};
new OrderArray14().reOrderArray(array);
}
}