白琳大佬带带我0001排序算法的模板

排序算法的模板//伪代码框架
我有一个小师弟我从来也不提


public class Sortexample {
    
    
	public static void sort(Compareable []) {
    
    
		
	} //选择排序算法
	private static boolean less(Comparable v, Comparable w) {
    
    
		return v.compareTo(w);//返回大于小于等于的值
	}//判断v和w是否按前后顺序排序
	private static void exch(Comparable[] a,int i,int j) {
    
    
		Comparable t=a[i];
		a[i]=a[j];
		a[j]=t;
	}//交换排序
	private static void show(Comparable []a) {
    
    
		for (int i=0;i<a.length;i++)
			System.out.print(a[i]+" ");
		System.out.println();
	}//输出排序序列
	public static boolean isSorted(Comparable [] a) {
    
    
		for(int i=0;i<a.length;i++)
			if(less(a[i],a[i-1])) return false;
			else return true;
	}//检验是否排序成功
	public static void main(String[] args) {
    
    
		String[] a=In.readstrings();
		sort(a);
		assert isSorted(a);
		show (a);
		
	}

}

猜你喜欢

转载自blog.csdn.net/qq_45864370/article/details/108902627