// TRAI_24_27.java SJ import java.util.*; public class TRAI_24_t27_skeleton { public static void main(String[] args) { int N = 7; if (args.length > 0) N = Integer.parseInt(args[0]); List> LL = new LinkedList<>(); Random r = new Random(N + 1); System.out.println("Input lists:"); for (int i = 0; i < N; i++) { List L = new LinkedList<>(); int ni = r.nextInt(N*2); for (int j = 0; j < ni; j++) { L.add(r.nextInt(N * 2)); } LL.add(L); System.out.println("L" + i + ": " + L); } LinkedList> LS = new LinkedList<>(LL); System.out.println("List list:"); printByLines(LS); sortBySize(LS); System.out.println("Listlist sorted according to number of elements:"); printByLines(LS); } // main() /** * Print collection by lines * * @param CC input collection * @param element type */ static void printByLines(Collection CC) { System.out.println("("); for (E x : CC) { System.out.println(x.toString()); } System.out.println(")"); } /** * 27. Write an algorithm that takes as a parameter a list of lists (List>) and * sorts the list based on the number of elements in the lists. * Hint: Collections.sort() or List.sort() and Comparator. * What is the time complexity of your algorithm? * * @param LS lista * @param joukkojen alkiotyyppi (ei käytetä) */ public static void sortBySize(List> LS) { // TODO } // remove comment marks around this class /* static class sizeComparator implements Comparator { // TODO: // hint: try Generate -> Implement Methods of your IDE } */ } // class