Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: converting ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 26148 of 28006
Post > Topic >>

Re: converting recursive function to iterative

by CBFalconer <cbfalconer@[EMAIL PROTECTED] > May 13, 2008 at 12:04 AM

V wrote:
> 
> Following is what I can think of...but it doesn't seem to be
> working ;- ( Any pointers...Thanks!
> 
> inline u64 multiplyPower_iter (u64 V, u8 i, u64 c)
> {
>    u64 result=1;
>    int j;
> 
>    if ((i == 0))
>         return V;
>    else
>    {
>         {
>                 while (i--)
>                 {
>                     result *= 2;
>                 }
> 
>                 result *= mul (V,c);
>         }
>         return result;
>    }
> }

I have no idea what this is about, since you didn't bother to quote
anything.  However, consider how much more understandable the above
is when written (generating same code) as: 

inline u64 multiplyPower_iter(u64 V, u8 i, u64 c)
{
   u64 result = 1;
   int j;

   if (i) {
      while (i--) result *= 2;
      return result * mul(V, c);
   }
   else return V;
}

-- 
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: <http://cbfalconer.home.att.net>
            Try the download section.


** Posted from http://www.teranews.com
**
 




 6 Posts in Topic:
converting recursive function to iterative
V <vishal.study@[EMAIL  2008-05-11 04:21:27 
Re: converting recursive function to iterative
Spiros Bousbouras <spi  2008-05-11 04:45:04 
Re: converting recursive function to iterative
V <vishal.study@[EMAIL  2008-05-12 18:54:44 
Re: converting recursive function to iterative
V <vishal.study@[EMAIL  2008-05-12 19:04:48 
Re: converting recursive function to iterative
CBFalconer <cbfalconer  2008-05-13 00:04:05 
Re: converting recursive function to iterative
Ben Bacarisse <ben.use  2008-05-13 15:08:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 14:39:34 CST 2008.