开发者

recursive to iterative

I have this function, and I want to change it to an iterative one. Does anyone know how to do it?

#include "list.h"

int count(LINK head)
{

if(head == NULL)开发者_如何学Python
   return 0;
else
   return (1 + count(head -> next));
}


int count(LINK head)
{
    int count = 0;
    while(head != NULL)
    {
        head = head->next;
        count = count + 1;
    }
    return count;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜