//方案一:優化
public class Solution {code
public void reOrderArray(int [] array) { int len=array.length; if(len==0) return; int start=0; for(int i=0;i<len;i++){ if(array[i]%2==1){ move(array,start,i); start=start+1; } } } public void move(int a[],int start,int end){ int temp=a[end]; int i=0; for(i=end;i>start;i--) a[i]=a[i-1]; a[i]=temp; }
}io
//方案二class
public class Solution {co
public void reOrderArray(int [] array) { int len=array.length; if(len==0) return; int temp; for(int i=0;i<len;i++) for(int j=0;j<len-i-1;j++) if(array[j]%2==0&&array[j+1]%2==1) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } }
}return
//方案三:對方案二的稍微優化void
public class Solution {tar
public void reOrderArray(int [] array) { int len=array.length; if(len==0) return; int temp; boolean flag=false; for(int i=0;i<len;i++){ for(int j=0;j<len-i-1;j++) if(array[j]%2==0&&array[j+1]%2==1) { temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; flag=true; } if(!flag) return; } }
}