我有这个功能,我想把它改成迭代的。有谁知道怎么做?
#include "list.h"
int count(LINK head)
{
if(head == NULL)
return 0;
else
return (1 + count(head -> next));
}
答案 0 :(得分:5)
int count(LINK head)
{
int count = 0;
while(head != NULL)
{
head = head->next;
count = count + 1;
}
return count;
}