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)
return 0;
else
return (1 + count(head -> next));
}
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)
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;
}