常见递归算法
编程实现斐波那契数列求值 f(n)=f(n-1)+f(n-2)¶
编程实现求阶乘 n!¶
编程实现一组数据集合的全排列¶
//全排列
public void permute(char[] chars, int start, int end){
if(start == end){
System.out.println(chars);
}else{
for(int i=start;i<=end;i++){
swap(chars, start,i);
permute(chars,start+1,end);
swap(chars, start,i);
}
}
}
public void swap(char[] chars, int i, int j){
char temp = chars[i];
chars[i] = chars[j];
chars[j] = temp;
}