🎉 One-stop destination for all your technical interview Preparation 🎉
int count(struct Node *head, int search_for)
{
struct Node *temp = head;
int cnt = 0;
while (temp != NULL)
{
if (temp->data == search_for)
cnt++;
temp = temp->next;
}
return cnt;
}
count(head, key);
if head is NULL
return frequency
if(head->data==key)
increase frequency by 1
count(head->next, key)
int countRec(struct Node *head, int search_for)
{
if (head == NULL)
return 0;
if (head->data == search_for)
return 1 + countRec(head->next, search_for);
return countRec(head->next, search_for);
}