算法备忘录----插入排序

public class InsertSort {
	
	public static void main(String[] args) {
		int[] old = {1,3,3,67,214234,34,9,34314,56,1};
		sort(old);
		print(old);

	}

	public static void sort(int[] a){
		for(int i=1;i<a.length;i++){
			int temp = a[i];
			int inner = i;
			while(temp<a[inner-1] && inner>0){
				a[inner] = a[inner-1];
				inner--;
			}
			a[inner] = temp;
		}
	}
	
	public static void print(int[] a){
		for(int i=0;i<a.length;i++){
			System.out.print(a[i]+" ");
		}
	}
}

你可能感兴趣的:(算法)