首页 > 编程语言 > 详细

Java实现全排序

时间:2020-04-29 15:30:05      阅读:76      评论:0      收藏:0      [点我收藏+]
package org.example.test;

import java.util.Stack;

public class QuanPaiXu {

  public static void main(String[] args) {
    perm(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, new Stack<Integer>());
  }

  public static void perm(int[] array, Stack<Integer> stack) {
    if (array.length == 0) {
      System.out.println(stack);
    } else {
      for (int i = 0; i < array.length; i++) {
        int[] tempArray = new int[array.length - 1];
        System.arraycopy(array, 0, tempArray, 0, i);
        System.arraycopy(array, i + 1, tempArray, i, array.length - i - 1);
        stack.push(array[i]);
        perm(tempArray, stack);
        stack.pop();
      }
    }
  }

}

原始链接:
https://blog.csdn.net/weixin_42220532/article/details/90900815

Java实现全排序

原文:https://www.cnblogs.com/mengjianzhou/p/12801856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!