现在的位置: 首页 > 综合 > 正文

java冒泡排序

2013年11月07日 ⁄ 综合 ⁄ 共 400字 ⁄ 字号 评论关闭
public class TestHashMap {
	final String a = "100";
	public static void main(String[] args) {
		TestHashMap testHashMap = new TestHashMap();
		int[] res = {12,32,3,43,2,45,23,10};
		testHashMap.Sort(res);
	}
	
	private void Sort(int[] res)
	{
		if (res.length != 0) {
			
			for (int i = 1; i < res.length; i++) {
				for (int j = res.length - 1; j >= i; j--) {
					if (res[j] > res[j - 1]) {
						int z = res[j];
						res[j] = res[j - 1];
						res[j - 1] = z;
					}
				}
			}
			
			for(int i = 0; i < res.length; i++)
			{
				System.out.println(res[i]);
			}
		}
	}
}

抱歉!评论已关闭.