冒泡排序
算法思想反复扫描待排序记录的序列,在扫描的过程中顺次比较相邻的两个元素大小,若如需就交换位置。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package paixu;
public class PaiXu {
public static void main(String[] args) {
int []a={48,62,35,77,55,14,35,98};
Bubblesort(a,a.length);
for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
public static void Bubblesort(int[] a, int n) {
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1-i;j++){
if(a[j]>a[j+1]){
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
}
来源:CSDN
作者:m0_45221093
链接:https://blog.csdn.net/m0_45221093/article/details/103585378