码迷,mamicode.com
首页 > 编程语言 > 详细

数组的冒泡排序方法展示

时间:2016-09-07 20:58:12      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

package cn.itcast;

public class pubbleSort {
	public static void main(String[] args) {
		int[] arr = { 84, 65, 95, 8, 63, 54, 25, 68, 47, 77, 58, 54, 69, 55, 58, 4, 5, 55, 48, 87, 45, 58, 54, 12, 25,
				49 };
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + "  ");
			if (i == arr.length - 1) {
				System.out.println("");
			}
		}
		System.out.println("--------------------------" );
		// 冒泡排序方法
		for (int i = 0; i < arr.length - 1; i++) {
			for (int x = 0; x < arr.length - 1-i; x++) {
				if (arr[x] > arr[x + 1]) {
					// 数值交换
					int a = arr[x];
					arr[x] = arr[x + 1];
					arr[x + 1] = a;
				}
			}
	     }
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + "  ");
			if (i == arr.length - 1) {
				System.out.println("");
			}
		}
	}
}

  

数组的冒泡排序方法展示

标签:

原文地址:http://www.cnblogs.com/whj-1994/p/5850829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!