没有测试过,有问题来http://www.douban.com/note/66682462/ 回复
(1)递归算法
long M-to-X(M-number)
{
/*
M mod 8 , output their remainders in reverse order
M-number is the individor
*/
long r = 0; //remainder
long R = 0; //result
if (M-number < 8)
{
return M-number;
}
else
{
r = M-number % 8;
R = M-number / 8;
return r + M-to-X(R) * 10;
}
}
(2)非递归算法,用栈实
long M-to-X(M-number)
{
/*
M mod 8 , output their remainders in reverse order
M-number is the individor
*/
long r = 0; //remainder
long R = 0; //result
long OX = 0; //OX-number
do{
r = M-number % 8;
R = M-number / 8;
push(s, r);
}while (R > 8);
while(!isEmpty(s)) /*s is a stack*/
{
OX = OX * 10 + pop(s);
}
printf("M-number = [%ld], is to OX-number = [%ld]\n", M-number, OX);
return OX;
}