字符串组合全排序 以及一串数的字串

按照顺序 以及加入选与不选的问题 采用递归方法表达 并在每一条执行函数中加入参数保存当前字符串的情况

当判断完毕时 输出该字符串
小范围还好 大范围则可能会溢出
求字符串子串 模板 里面会多一种"" 空字符串

import java.util.*;
public class Main {
	public static void funcation(String s, int num, String res) {
		if (num == s.length())
			System.out.println(res);
		else {
			funcation(s, num + 1, res + s.charAt(num));
			funcation(s, num + 1, res);
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String res = "";
		int num = 0;
		funcation(s, num, res);
	}
}

栈的写法

public static void combine(char chs[]){  
    if(chs.length == 0) return ;  
      
    Stack<Character> stack = new Stack<Character>();  
    for(int i = 1; i <= chs.length; i++){  
        combine(chs, 0, i, stack);  
    }  
}  
//从字符数组中第begin个字符开始挑选number个字符加入stack中  
public static void combine(char []chs, int begin, int number, Stack<Character> stack){  
       if(number == 0){  
        System.out.println(stack.toString());  
        return ;  
       }  
       if(begin == chs.length){  
        return;  
       }  
       stack.push(chs[begin]);  
       combine(chs, begin + 1, number - 1, stack);  
       stack.pop();  
       combine(chs, begin + 1, number, stack);  
}  

搜索中看到一些文章 插在这里把https://blog.csdn.net/morewindows/article/details/7370155

这种思路好像行得通 不过截图的具体实现有误
来自https://www.cnblogs.com/lifegoesonitself/p/3225803.html
里面有介绍其他的方法 http://zhedahht.blog.163.com/blog/static/2541117420114172812217/
这篇是用二进制来的https://blog.csdn.net/fxkcsdn/article/details/81328089

原文地址:https://www.cnblogs.com/cznczai/p/11149911.html