标签:als java 排序 int oid stat turn vat read
算法 第4版
public class example{ public static void sort(Comparable[] a) { /*排序算法*/} private static boolean less(Comparable v, Comparable w) { return v.Comparable(w) < 0; } private static void exch(Comparable[] a, int i, intj ) {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++) StdOut.print(a[i] + " " ); StdOut.println(); } public static boolean isSorted(Comparable[] a) { for(int i = 1; i < a.length) if( less(a[i],a[i-1]) ) return false; return true; } public static void main(String[] args) { String[] a = In.readStrings(); sort(a); assert isSorted(a); show(a); } }
标签:als java 排序 int oid stat turn vat read
原文地址:https://www.cnblogs.com/chenshuo754/p/9508857.html