冒泡排序

Posted wangsihui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了冒泡排序相关的知识,希望对你有一定的参考价值。

package blog;

import java.util.Arrays;

public class bubble {

	public static void main(String[] args) {
		int[] a = new int[] {9,5,7,4,0,3};
		asc(a);
		System.out.println(Arrays.toString(a));
	}
	
	static void asc(int [] arr) {
		int temp;
		for(int i=0;i<arr.length-1;i++) {
			for(int j=0;j<arr.length-1-i;j++) {
				if(arr[j+1] < arr[j]) {
				    temp = arr[j];
					arr[j] = arr[j+1];
					arr[j+1] = temp;
				}
			}
		}
	}
}
技术图片

  

以上是关于冒泡排序的主要内容,如果未能解决你的问题,请参考以下文章