选取前200条记录,冒泡排序

降序排,a表示待排序的数组,b记录a对应原先的位置,跟着一起变化
for (int i = 0; i < 200; i++)中200表示做了200次冒泡排序,这样节省很多时间,没进行一次冒泡排序,最大值会排到最前面,再排一次,次大的会在第二个位置,这样200次就能取到由高到低200条,对于大的数组来说,不用全部排序就可知结果

    public static double[] bubbleSort(double[] a,int[] b) 
    {  
        for (int i = 0; i < 200; i++)
        {  
            for (int j = i + 1; j < a.length; j++)
            {  
                if(a[i] < a[j])
                {  
                    double temp;
                    int temp1; 
                    temp = a[j];  
                    a[j] = a[i];  
                    a[i] = temp;  
                    temp1 = b[j];  
                    b[j] = b[i];  
                    b[i] = temp1;  

                }  
            }  
        }  
        return a;  
    }

你可能感兴趣的:(冒泡排序)