题1 数组排序 奇数在前 偶数在后

题一 数组排序 奇数在前 偶数在后


	 public static void main (String [] args ){
		   int a [] =  {1,2,4,3,6,7,9};
		   int start =0;
		   int temp;
		   int end = a.length-1;
		   while(start!=end){
			   if((a[start]%2==0)&&(a[end]%2!=0)){
				   temp = a[start];
				   a[start]=a[end];
				   a[end]=temp;
				   end--;
			   }
			   start++;
		   }
		   
		   for(int i=0;i<a.length;i++){
			   System.out.println(a[i]);
		   }
	 }

设置前后两个指针,一个指向开始的位置,一个指向结尾的位置,当两个指针从何的时候程序结束
1 楼 9941052 2011-11-19  
按你这种做法,设int a [] =  {1,2,4,3,6,7}; 
就会输出:1 7 4 3 6 2
比如,我如果是4,3,6 程序输出还是4,3,6