相關講義
import java.security.SecureRandom;
import java.util.Arrays;
public class bubbleSort
{
    static void bubbleSort(int [] data)
    {
        int temp;
        for (int i=data.length-1; i>0; i--)
            for (int j=0;j<i;j++)
                if (data[j]>data[j+1])
                {
                    temp=data[j];
                    data[j]=data[j+1];
                    data[j+1]=temp;
                }
        
    }
    
    public static void main(String [] argv)
    {
        SecureRandom rnd=new SecureRandom();
        int [] data=new int[26];
        int a,b;
        do
        {
            a=rnd.nextInt()%101;
            if (a<0) a+=101;
        } while (a==0);
        b=rnd.nextInt()%101+101;
        for (int i=0; i<26;i++)
        {
            data[i]=(a*i+b)%101;
            System.out.print("data["+i+"]="+data[i]+"\t");
        }
        System.out.println("\nBefore Sorting!");        
    //  bubbleSort(data);
        Arrays.sort(data); //quick sort
        for (int i=0;i<26;i++)
            System.out.print("data["+i+"]="+data[i]+"\t");
        System.out.println("\nAfter Sorting!");
    }
}
herrDeng網內搜尋
 
  
    自訂搜尋
  
Ads
2010年5月13日 星期四
熱門文章
- 
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
- 
連續複利
- 
請用Random產生20個0~99的奇數(可重複),然後排序
- 
py3 cpp Line sweep解Leetcode 3346 Maximum Frequency of an Element After Performing Operations I 使用 line sweep不用排序,可得線性解 [Py3解請進]
- 
C++ Py3 計數排序與partial sum解Leetcode 2300 Successful Pairs of Spells and Potions Portions的極大值小於等於10萬是可進行記數排序的關鍵,既然可以採用記數排序,後面的二元搜尋也可以透過part...
- 
Py3 C++ C 2pointer速解Leetcode 11Container With Most Water [Py3 code請進]
- 
輸入公元n年,輸出"平年" "閏年"
- 
Py3 C++計數bitmask與2 pointers速解Leetcode2273 Find Resultant Array After Removing Anagrams 字串長度最長也只有10,四個bits一組,用bitmask解題 ----- The maximum le...

 
 
