java算法之冒泡排序

package com.hym.test;

public class PopSort {
	int[] arrayTest = { 5, 26, 1, 783, 23, 2, 62, 9, 46 };

	public void sort() {
		for (int i = 0; i < arrayTest.length; i++) {
			for (int j = 0; j < arrayTest.length - i; j++) {
				if ((j + 1 < arrayTest.length)
						&& arrayTest[j] > arrayTest[j + 1]) {
					int temp = arrayTest[j];
					arrayTest[j] = arrayTest[j + 1];
					arrayTest[j + 1] = temp;
				}
			}
		}
	}

	public static void main(String[] args) {
		PopSort sort = new PopSort();
		sort.sort();
		for (int i = 0; i < sort.arrayTest.length; i++) {
			System.out.print(sort.arrayTest[i] + " ");
		}
	}
}



http://baike.baidu.com/view/254413.htm

你可能感兴趣的:(java算法)