package com.org.arrays.sort;
//插入排序法
public class TestInsert {
	/**
	 * @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();
		insertSort(ary);
		System.out.print("整数排序后:");
		for (int a : ary) {
			System.out.print(a + "\t");
		}
	}
	/** 插入排序 */
	public static int[] insertSort(int[] ary) {
		int i, j, t;
		for (i = 1; i < ary.length; i++) {
			t = ary[i];
			for (j = i - 1; j >= 0; j--) {
				if (t < ary[j]) {
					ary[j + 1] = ary[j];
				} else {
					break;
				}
			}
			ary[j + 1] = t;
		}
		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日
            
            
         最近浏览更多
最近浏览更多
                
                13543528515     LV8
                2024年5月21日
            
            
        
                sky1044     LV1
                2024年2月19日
            
            
        
                1112WHQ     LV7
                2023年11月3日
            
            
        
                EFWAGGFAWGR    
                2023年10月19日
            
            
                    暂无贡献等级
            
        
                llxxtt     LV2
                2023年6月5日
            
            
        
                wuziayng1232     LV11
                2023年2月21日
            
            
        
                insane1     LV1
                2022年12月6日
            
            
        
                jjfskldjf     LV2
                2022年11月27日
            
            
        
                微信网友_6040315240812544     LV8
                2022年10月27日
            
            
        
                18214966423     LV2
                2022年9月6日
            
            
        
 
                 
                 
                