阿克曼(Ackerman)函数问题的记录
2019-08-07 本文已影响0人
fastcv
函数定义 ack(m,n) = n+1 (m == 0) / ack(m,n) = ack(m-1,1) (n == 0) / ack(m,n) = ack(m-1,ack(m,n-1))
解:
public class Ackerman {
public static void main(String[] args) {
System.out.println(" " + ack(3,4) + "");
}
public static int ack(int m,int n){
if ( m == 0){
return n+1;
}else if (n == 0){
return ack(m-1,1);
}else {
return ack(m-1,ack(m,n-1));
}
}
}