Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Assign3_apergi {
- public static void swap(int[] b ,int x ,int y){
- int temp=b[x];
- b[x]=b[y];
- b[y]=temp;
- }
- public static void rearrangeArray(int[] b){
- int k=0;
- for(int i=0; i < b.length; i++){
- if(b[i]<0){
- swap(b,i,k);
- k++;
- }
- }
- int m=k;
- for(int i=k; i < b.length; i++){
- if(b[i]==0){
- swap(b,i,m);
- m++;
- }
- }
- }
- public static void main(String args[]){
- int b[] = {1,0,-3,0,7,-1,0,9,-9,-8,0};
- rearrangeArray(b);
- for(int i=0; i < b.length; i++){
- System.out.print(b[i]+" ");
- }
- }
- }
Add Comment
Please, Sign In to add comment