首页>代码>java四种排序算法>/sort/TestCheck.java
package com.org.arrays.sort;

//选择排序法
public class TestCheck {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int [] ary = {-1,-3,5,7,9,2,4,6,8,10};
		System.out.print("整数排序前:");     
		for(int ar:ary){
			System.out.print(ar+"\t");
		}
		System.out.println();
		selectSort(ary);
		System.out.print("整数排序后:");
		for(int a:ary){
			System.out.print(a+"\t");
		}
		
	}

	 /** 冒泡排序方法  */    
	/*private static void displayIntArr(int[] arr) {

		for(int i=arr.length-1;i>0;i--){
			for(int j=0;j<i;j++){
				if(arr[j]>arr[j+1]){
					int temp;
					temp = arr[j];
					arr[j] = arr[j+1];
					arr[j+1] = temp;
				}
			}
		}
	}*/
	
	/** 选择排序 */
    public static int[] selectSort(int[] ary) {
        for (int i = 0; i < ary.length - 1; i++) {
              for (int j = i + 1; j < ary.length; j++) {
                  if (ary[i] > ary[j]) {
                      int temp = ary[i];
                      ary[i] = ary[j];
                      ary[j] = temp;
                  }
              }
        }
        return ary;
    }
}
最近下载更多
姜广坤  LV14 2022年5月20日
tangjj7260  LV18 2021年11月18日
ysh11433  LV2 2020年9月1日
15286210829  LV8 2020年7月20日
moomin709  LV24 2020年7月6日
frunk_fu  LV7 2020年3月5日
不舒服就啊发  LV4 2019年12月29日
数据库1  LV12 2019年10月28日
seanc326  LV2 2019年8月17日
yunshuo  LV1 2019年5月25日
最近浏览更多
sky1044  LV1 2月19日
1112WHQ  LV7 2023年11月3日
EFWAGGFAWGR 2023年10月19日
暂无贡献等级
llxxtt  LV2 2023年6月5日
wuziayng1232  LV10 2023年2月21日
insane1  LV1 2022年12月6日
jjfskldjf  LV2 2022年11月27日
微信网友_6040315240812544  LV8 2022年10月27日
18214966423  LV2 2022年9月6日
泽泽zz 2022年7月1日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友