-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort01.java
More file actions
70 lines (35 loc) · 878 Bytes
/
Copy pathsort01.java
File metadata and controls
70 lines (35 loc) · 878 Bytes
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package arrays;
public class sort01 {
public static void helper2(int[] arr) {
int l = 0;
int h = arr.length - 1;
while (l < h) {
if (arr[l] == 0) {
l++;
} else if (arr[h] == 1) {
h--;
} else if (arr[l] == 1 && arr[h] == 0) {
int temp = arr[l];
arr[l] = arr[h];
arr[h] = temp;
}
}
}
public static void main(String[] args) {
int arr[]={0,1,1,0,1,0,1};
int n=7;
int zero=0,curr=0;
while(curr<n){
if(arr[curr]==0){
int temp=arr[curr];
arr[curr]=arr[zero];
arr[zero]=temp;
zero++;
}
curr++;
}
for(int i=0;i<n;i++){
System.out.println(arr[i]);
}
}
}