冒泡排序

Posted 雪落无痕1

tags:

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

1. 冒泡排序

 

 

 

 

 

import java.util.Arrays;

public class BubbleSort {
	public static void main(String[] args) {
		int[] ary={16,76,23,1,49,15,2};
		
		sort(ary);
		System.out.println(Arrays.toString(ary));
	}
	public static void sort(int[] ary1) {
		for (int i = 0; i < ary1.length - 1; i++) {
			for (int j = 0; j < ary1.length - i - 1; j++) {
				if (ary1[i] > ary1[j]) {
					int t = ary1[i];
					ary1[i] = ary1[j];
					ary1[j] = t;
				}
			}
		}
	}
}

 

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