您的位置:首页 > 其它

冒泡排序

2015-10-13 14:12 411 查看
[code]package com.hongyewell.com;

/**
 * 冒泡排序
 * 借助变量temp来对数组中相邻的两个元素进行比较
 * @author yeye
 *
 */

public class BubbleSort {

    public static void main(String[] args){
        int arr[] ={2,3,4,8,9,10,1,5,6,7};
        int temp;
        for(int i=0;i<10;i++){
             temp = arr[i];
            for(int j=0;j<10;j++){
                if(arr[i]<arr[j]){
                    temp =arr[j];
                    arr[j]=arr[i];
                    arr[i]=temp;
                }
            }
        }
        for(int n:arr){
            System.out.println(n);
        }

    }

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: