zoukankan      html  css  js  c++  java
  • 几种排序算法

    public class Bubble {
    
    	public static void main(String[] args) {
    		int[] a = {38, 17, 16, 16, 7, 31, 39, 32, 2, 11};
    		for(int i = 0;i<a.length;i++){
    			for(int j=i+1;j<a.length;j++){
    				if(a[j]<a[i]){
    					exchange(a,i,j);	
    				}
    			}
    		}
    		for(Integer x:a){
    			System.out.print(" "+x);
    		}
    	}
    	
    	public static void exchange(int[] array,int i, int j){
    		if(i == j){return;}
    		int temp = array[i];
    		array[i] = array[j];
    		array[j] = temp;
    	}
    }
    

      

    public class Insert {
    
    	public static void main(String[] args) {
    		int[] a = {38, 17, 16, 16, 7, 31, 39, 32, 2, 11};
    		for(int i = 1;i<a.length;i++){
    			int temp = a[i];
    			int j = i;
    			for(;j>0;j--){
    				if(a[j-1]>temp){
    					a[j] = a[j-1];
    				}else{
    					break;
    				}
    			}
    			a[j] = temp;
    		}
    		for(Integer x:a){
    			System.out.print(" "+x);
    		}
    	}
    }
    

      

    public class Quick {
    
    	public static void main(String[] args) {
    		int[] a = {41,59,43,26,63,30,29,26,42};
    		
    		sort(a,0,a.length-1);
    		
    		for(Integer x:a){
    			System.out.print(" "+x);
    		}
    	}
    
    
    	private static void sort(int[] array, int lo, int hi) {
    		if (lo >= hi) {
    			return;
    		}
    
    		int toFinal = array[lo];
    		int leftIdx = lo;
    		int rightIdx = hi;
    
    		int i = lo + 1;
    
    		while (i <= rightIdx) {
    			if (array[i] == toFinal) {
    				i++;
    			} else if (array[i] < toFinal) {
    				exchange(array, leftIdx++, i++);
    			} else {
    				exchange(array, rightIdx--, i);
    			}
    		}
    
    		sort(array, lo, leftIdx - 1);
    		sort(array, rightIdx + 1, hi);
    	}
    	
    	public static void exchange(int[] array,int i, int j){
    		if(i == j){return;}
    		int temp = array[i];
    		array[i] = array[j];
    		array[j] = temp;
    	}
    }
    

      

    public class Select {
    
    	public static void main(String[] args) {
    		int[] a = {38, 17, 16, 16, 7, 31, 39, 32, 2, 11};
    		for(int i = 0;i<a.length;i++){
    			int selected = i;
    			for(int j=i+1;j<a.length;j++){
    				if(a[j]<a[selected]){
    					selected = j;
    				}
    			}
    			
    		exchange(a,i,selected);	
    		}
    		for(Integer x:a){
    			System.out.print(" "+x);
    		}
    	}
    	
    	public static void exchange(int[] array,int i, int j){
    		if(i == j){return;}
    		int temp = array[i];
    		array[i] = array[j];
    		array[j] = temp;
    	}
    
    }
    

      

  • 相关阅读:
    Charpter5 软件测试总结
    Charpter3 关于闰年测试
    Charpter2 新的测试用例
    Charpter1 等价类划分方法分析与应用
    软件测试第一周学习总结
    关于软件测试学习的心得
    软件测试-同行评审
    白盒测试
    黑盒测试
    Java实现的闰年测试程序
  • 原文地址:https://www.cnblogs.com/charles-dxb/p/3586540.html
Copyright © 2011-2022 走看看