Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Question2
- {
- public static void sortByFour(int[] arr)
- {
- int first=0;
- while(arr[first]%4==0 && first<arr.length)
- first++;
- int last=arr.length-1;
- while(arr[last]%4==3 && last>=0)
- last--;
- int temp=0;
- int pivot;
- for(pivot=first; pivot<=last; pivot++)
- {
- if(arr[pivot]%4==1)
- {
- temp=arr[pivot];
- arr[pivot]=arr[first];
- arr[first]=temp;
- pivot++;
- first++;
- }
- else if(arr[pivot]%4==2)
- {
- temp = arr[pivot];
- arr[pivot] = arr[last];
- arr[last] = temp;
- last--;
- }
- else
- pivot++
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement