自己实现全排列:I found some old code were good:We should think in a reverse way
2009-06-23 16:30
507 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace zuhe
{
class Program
{
static public void zuhe(char[] c, StringBuilder s, int level)
{
for (int i = level; i < c.Length; i++)
{
s.Append(c[i]);
Console.WriteLine(s);
if (level < c.Length - 1)
{
level++;
zuhe(c, s,level);
}
s.Length -= 1; //setting lower length to differ the new stringbuider from the old
}
}
static void Main(string[] args)
{
string me = "abcd";
char[] my = me.ToCharArray();
StringBuilder sb = new StringBuilder();
zuhe(my, sb, 0);
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace zuhe
{
class Program
{
static public void zuhe(char[] c, StringBuilder s, int level)
{
for (int i = level; i < c.Length; i++)
{
s.Append(c[i]);
Console.WriteLine(s);
if (level < c.Length - 1)
{
level++;
zuhe(c, s,level);
}
s.Length -= 1; //setting lower length to differ the new stringbuider from the old
}
}
static void Main(string[] args)
{
string me = "abcd";
char[] my = me.ToCharArray();
StringBuilder sb = new StringBuilder();
zuhe(my, sb, 0);
Console.ReadKey();
}
}
}
相关文章推荐
- Why did we implement Swing in this way?(为什么Swing要这样实现呢?)
- Every student in every school should have the opportunity to learn to code
- . 有一个一维数组,里面存储整形数据,请写一个函数,将他们按从大到小的顺序排列,要求执行效率高,并说明如何改善执行效率(该函数必须自己实现,不能使用php函数)。
- 实现自己的http server - loop_in_codes - C++博客
- EclipsePlug-in使用TextEditor开发自己的编辑器,实现关键字高亮和代码提示.
- Android打包报错 Export aborted because fatal lint errors were found. These are listed in the Lint View
- EclipsePlug-in使用TextEditor开发自己的编辑器,实现关键字高亮和代码提示.
- Code First 启用迁移时出错 "No context type was found in the assembly"
- 模块化思想:创建一个数组, 实现函数init()初始化数组、 实现empty()清空数组、 实现reverse()函数完成数组元素的逆置。 要求:自己设计函数的参数,返回值。
- What is the best way to handle Invalid CSRF token found in the request when session times out in Spring security
- SBT-Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
- 【C语言】编写一个函数reverse_string(char * string)(递归实现),将参数字符串中的字符反向排列,不能使用C函数库中的字符串操作函数。
- LeetCode:reverse words in a string---两种方法实现
- 自己写的日志框架--linkinLog4j--实现基本的框架功能
- 【think in java】 实现Stack
- Think in Code,用代码思考
- Why we should overwrite the hashCode() when we overwrite the equals()
- Leet Code Binary Tree Inorder Traversal(非递归且实现不用栈的空间复杂度为O(1)的实现)
- 雇佣问题原址排列给定数组(randomize In Place)-c++代码实现及运行实例结果
- 项目打包签名时候报:Export aborted because fatal lint errors were found these are listed in the lint view...