算法一 冒泡排序

 1 public class BubbleSort{
 2     public static void main(String args[]){
 3         BubbleSort bubbleSort=new BubbleSort();
 4 
 5         int arr_test[]={5,6,2,1,9};
 6         bubbleSort.bubbleSort(arr_test);
 7         for(int num:arr_test){
 8             System.out.print(num+" ");
 9         }
10     }
11 
12     public void bubbleSort(int arr[]){
13         int tmp;
14         for(int i=0;i<arr.length;i++){
15             for(int j=0;j<arr.length-1-i;j++){
16                 if(arr[j]>arr[j+1]){
17                     tmp=arr[j];
18                     arr[j]=arr[j+1];
19                     arr[j+1]=tmp;
20                 }
21             }
22         }
23 
24     }
25 }

 

posted @ 2019-07-15 11:44  zhaozishuang  阅读(144)  评论(0编辑  收藏  举报