Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CombinationTest{
- public static void main(String[] args) {
- listCombination(new char[]{'a','b','c'});
- }
- public static void listCombination(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);
- }
- }
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement