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);
}
}
}
冒泡排序
最新推荐文章于 2023-06-06 09:14:05 发布