面试题:输入一个整数,使用递归方法实现反向输出
int RevOutInt(int iIntput)
{
static unsigned int i = 0;
static unsigned int j,k;
k = iIntput%10;
j = iIntput/10;
i = 10*i+k;
if(0==j)
return i;
RevOutInt(j);
}
此方法没有考虑算法的时间和空间复杂度。征求较优实现方法
本文深入探讨了利用递归方法实现整数反向输出的过程,并指出了现有方法在时间和空间复杂度上的局限性。通过分析,提出了改进算法以优化性能,同时详细阐述了关键步骤和技术细节。
面试题:输入一个整数,使用递归方法实现反向输出
int RevOutInt(int iIntput)
{
static unsigned int i = 0;
static unsigned int j,k;
k = iIntput%10;
j = iIntput/10;
i = 10*i+k;
if(0==j)
return i;
RevOutInt(j);
}
此方法没有考虑算法的时间和空间复杂度。征求较优实现方法
1258