当前所在位置:珠峰网资料 >> 计算机 >> 软件水平 >> 正文
2015年软考程序员算法实例:全排列的递归算法
发布时间:2011/3/18 10:50:13 来源:城市学习网 编辑:ziteng
  using System;
  namespace TotalSort
  {
  /**////
  /// 全排列的递归算法
  ///
  class Class1
  {
  /**////
  /// 应用程序的主入口点。
  ///
  [STAThread]
  static void Main(string[] args)
  {
  //char[] s = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
  char[] s = "abcde".ToCharArray();
  TotalSort(s, 0);
  Console.WriteLine("\n\n总数:{0}", resultCount);
  Console.ReadLine();
  }
  static int resultCount = 0;
  public static void TotalSort(char[] list, int start) {
  int end = list.Length - 1;
  if (start == end) {
  resultCount++;
  Console.WriteLine(list);
  }
  else {
  for (int i = start; i <= end; i++) {
  char[] temp = new char[list.Length];
  list.CopyTo(temp, 0);
  char tempc = temp[start];
  temp[start] = temp[i];
  temp[i] = tempc;
  TotalSort(temp, start + 1);
  }
  }
  }
  }
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved