冒泡排序(随机取25个整数进行排序)

 1 import java.util.ArrayList;
 2 import java.util.List;
 3 import java.util.Random;
 4 
 5 public class Maopao {
 6 
 7  /**
 8   * @param args
 9   */
10   
11  public List<Maopao> Max(int[] v) {
12   List lis=new ArrayList<Maopao>();
13   int x=v.length;
14   for (int j = x-1; j < x; j--){
15   for (int i = 0; i < j; i++) {
16    if (v[i] < v[i + 1]) {
17     int s; 
18     s = v[i];
19     v[i]=v[i+1];
20     v[i+1]=s;
21    }
22   }
23  }
24   for (int j = 0; j < x; j++){
25    lis.add(v[j]);
26   }
27   return lis;
28  }
29 
30  public static void main(String[] args) {
31   // TODO Auto-generated method stub
32    Random rand=new Random(47);
33    int[] intArray=new int[25];
34    for(int i=0;i<=intArray.length-1;i++){
35     intArray[i]=rand.nextInt(100);    
36    }
37   Maopao t=new Maopao();
38   List arr=t.Max(intArray);
39   
40   for(int i = 0; i<arr.size();i++){
41    System.out.print(arr.get(i)+" ");   
42   }
43 
44 
45  }
46 
47 }

 

posted @ 2012-11-04 20:42  hlb  阅读(291)  评论(0编辑  收藏  举报