-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort012
40 lines (39 loc) · 942 Bytes
/
sort012
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
import java.util.* ;
import java.io.*;
public class Solution
{
public static void sort012(int[] a)
{
int low=0;
int high=a.length-1;
int mid=0;
while(mid<=high)
{
switch(a[mid])
{
case 0:
{
int temp=a[low];
a[low]=a[mid];
a[mid]=temp;
low++;
mid++;
break;
}
case 1:
{
mid++;
break;
}
case 2:
{
int temp=a[high];
a[high]=a[mid];
a[mid]=temp;
high--;
break;
}
}
}
}
}