import java.util.*; public class Main { public static boolean nextPermutation(List<Integer> list) { int i = list.size() - 2; while (i >= 0 && list.get(i) >= list.get(i + 1)) i--; if (i < 0) return false; int j = list.size() - 1; while (list.get(i) >= list.get(j)) j--; return true; } do { } while (nextPermutation(a)); } }
Standard input is empty
[1, 2, 3, 4] [1, 2, 4, 3] [1, 3, 2, 4] [1, 3, 4, 2] [1, 4, 2, 3] [1, 4, 3, 2] [2, 1, 3, 4] [2, 1, 4, 3] [2, 3, 1, 4] [2, 3, 4, 1] [2, 4, 1, 3] [2, 4, 3, 1] [3, 1, 2, 4] [3, 1, 4, 2] [3, 2, 1, 4] [3, 2, 4, 1] [3, 4, 1, 2] [3, 4, 2, 1] [4, 1, 2, 3] [4, 1, 3, 2] [4, 2, 1, 3] [4, 2, 3, 1] [4, 3, 1, 2] [4, 3, 2, 1]