码迷,mamicode.com
首页 > 编程语言 > 详细

Java实现全排序

时间:2020-04-29 14:22:54      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:test   details   org   static   https   void   out   http   temp   

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实现全排序

标签:test   details   org   static   https   void   out   http   temp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!