相關講義
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!");
}
}