选择排序、冒泡排序、工具类排序

package com.test.test;

import java.util.Arrays;

/**
 * [说明/描述]
 * 
 * @author CaiHaiming
 * @date 2016-6-4 下午7:00:07
 * @company chm
 * @version 1.0
 * @copyright copyright (c) 2016
 */
public class Sort1 {
	public static void main(String[] args) {
		int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };
		sort1(arr);
		System.out.println(Arrays.toString(arr));
	}

	public static void sort1(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] > arr[j]) {
					Sort2.swap(arr, i, j);
				}
			}
		}
	}
}

package com.test.test;


import java.util.Arrays;


/**
 * [说明/描述]
 * 
 * @author CaiHaiming
 * @date 2016-6-4 下午7:00:07
 * @company chm
 * @version 1.0
 * @copyright copyright (c) 2016
 */
public class Sort2 {
<span style="white-space:pre">	</span>public static void main(String[] args) {
<span style="white-space:pre">		</span>int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };
<span style="white-space:pre">		</span>sort1(arr);
<span style="white-space:pre">		</span>System.out.println(Arrays.toString(arr));
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public static void sort1(int[] arr) {
<span style="white-space:pre">		</span>for (int i = 0; i < arr.length - 1; i++) {
<span style="white-space:pre">			</span>for (int j = 0; j < arr.length - i - 1; j++) {
<span style="white-space:pre">				</span>if (arr[j] > arr[j + 1]) {
<span style="white-space:pre">					</span>swap(arr, j, j + 1);
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public static void swap(int[] arr, int i, int j) {
<span style="white-space:pre">		</span>int temp = arr[i];
<span style="white-space:pre">		</span>arr[i] = arr[j];
<span style="white-space:pre">		</span>arr[j] = temp;
<span style="white-space:pre">	</span>}
}


package com.test.test;


import static java.util.Arrays.sort;


import java.util.Arrays;


/**
 * [说明/描述]
 * 
 * @author CaiHaiming
 * @date 2016-6-4 下午7:00:07
 * @company chm
 * @version 1.0
 * @copyright copyright (c) 2016
 */
public class Sort3 {
<span style="white-space:pre">	</span>public static void main(String[] args) {
<span style="white-space:pre">		</span>int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };
<span style="white-space:pre">		</span>sort(arr);
<span style="white-space:pre">		</span>System.out.println(Arrays.toString(arr));
<span style="white-space:pre">	</span>}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值