Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void permutate(int ind, int []perm) {
- int n = perm.length;
- if (ind == n) {
- for (int i = 0 ; i < n; ++i) {
- System.out.print(perm[i] + "\t");
- }
- System.out.println();
- return;
- }
- for (int i = 0; i < n; ++i) {
- boolean flag = false;
- for (int k = 0; k < ind; ++k) {
- if (perm[k] == i) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- perm[ind] = i;
- permutate(ind + 1, perm);
- }
- }
- }
- public static void main(String []args) {
- int []perm = {-1, -1, -1, -1, -1};
- permutate(0, perm);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement