码迷,mamicode.com
首页 > 编程语言 > 详细

数组奇在偶前

时间:2014-10-10 16:08:50      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:os   ar   for   amp   new   as   dp   return   class   

public class shuzujizaihouzhiqian {

//private static final String[][] String = null;
/**
* @param args
* @return
*/
public static void sort(int[] x){
if(x==null||x.length==0){
return ;
}
int len=x.length;
int[] tmp=new int[len];
int oddPos=0;
int evenPos=len-1;
for(int i=0;i<len;i++){
if(!isEven(x[i])){
tmp[oddPos++]=x[i];
}else{
tmp[evenPos--]=x[i];
}
}
System.arraycopy(tmp, 0, x, 0, len);
}
public static boolean isEven(int x){
return (x&1)==0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] tem={1,2,5,4,9,34,97,35,68};
sort(tem);
String[] str=new String[tem.length];
for (int i = 0; i < tem.length; i++) {
str[i]=tem[i]+"";
System.out.print(str[i]+" ");
}

}

}

数组奇在偶前

标签:os   ar   for   amp   new   as   dp   return   class   

原文地址:http://www.cnblogs.com/linth/p/4015563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!