- public class Rank {
- public static void main(String[] args) {
- int[] array = { 7, 9, 5, 8 };
- boolean[] isSelected = new boolean[array.length];
- int[] array2 = new int[array.length];
- for (int i = 0; i < isSelected.length; i++) {
- isSelected[i] = false;
- }
- rankArray(array, isSelected, array2, 0);
- }
- public static void rankArray(int[] array, boolean[] isSelected,
- int[] array2, int length) {
- if (array.length == length) {
- for (int i : array2) {
- System.out.print(i + ",");
- }
- System.out.println();
- return;
- }
- for (int i = 0; i < isSelected.length; i++) {
- if (isSelected[i]) {
- continue;
- }
- isSelected[i] = true;
- array2[length] = array[i];
- rankArray(array, isSelected, array2, length + 1);
- isSelected[i] = false;
- }
- }
- }
复制代码 |