测试四种全排列

本文介绍了一个Java程序,该程序实现了不同的排列算法,包括升序排列、降序排列、邻位交换排列及字典序排列。用户可以选择不同的排列类型并输入排列规模进行测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package permutation;

import java.util.Scanner;

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("---------------start-------------");
		Scanner scan = new Scanner(System.in);
		System.out.println("Please choose  type of permutation:");
		System.out.println("0: ascend permutation,\t1: decline permutation,"
				+ "\n2: neighbour exchange permutation,  default: dictionary permutation :");
		int choose = scan.nextInt();
		long start = System.currentTimeMillis();
		while(choose>=0){
			System.out.println("Please input the scale of permutation: ");
			int scale = scan.nextInt();
			switch(choose){
				case 0 :
					System.out.println("ascend permutation:");
					AscendPermutation ap = new AscendPermutation(); 
					ap.ascendPermutationAlgorathim(ap.creatPermutation(scale));
					break;
				case 1 :
					System.out.println("decline permutation:");
					DeclinePermutation dp = new  DeclinePermutation ();
					dp.declinePermutationAlgorathim(dp.creatPermutation(scale));
					break;
				case 2 :
					System.out.println("neighbour exchange permutation:");
					NeighbourExchangePermutation nep = new NeighbourExchangePermutation();
					nep.neighbourExchangePermutation(nep.creatPermutation(scale));
					break;
				default :
					System.out.println("dictionary permutation:");
					DictionaryPermutation dictp = new DictionaryPermutation();
					dictp.permutation(dictp.creatPermutation(scale));
			}
			long end = System.currentTimeMillis();
		//	System.out.println("run time : " + (double)Math.round((end - start)/1000) + " Second ");
			System.out.println("run time : " +  (end - start) + " MillionSecond ");
			System.out.println("---------------end---------------\n\n");
			System.out.println("---------------start-------------");
			choose = scan.nextInt();
			start = System.currentTimeMillis();
		}
		System.out.println("---------------end---------------");
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值