开发者

recursive to iterative

开发者 https://www.devze.com 2023-02-28 18:33 出处:网络
I have this function, and I want to change it to an iterative one. Does anyone know how to do it? #include \"list.h\"

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

精彩评论

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