Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming Need function to count occurance of x int lst_count(LIST *l, ElemT

ID: 3767225 • Letter: C

Question

C Programming

Need function to count occurance of x

int lst_count(LIST *l, ElemType x) { return 0; } int lst_sanityl(LIST *l) { if(l rightarrow front == NULL && l rightarrow back != NULL){ fprintf(stderr, "lst_sanityl error: front NULL but back non-NULL "); return 0; if(l rightarrow back == NULL && l rightarrow front != NULL){ fprintf(stderr, "lst_sanityl error: back NULL but front non-WULL "); return 0; } return 1; } int lst_sanity2(LIST *l) { if(l rightarrow back != NULL && l rightarrow back rightarrow next != NULL) { fprintf (stderr, "lst_sanity2 error: back elem has a nonHSIULL next? "); return 0; } return 1;

Explanation / Answer

int lst_count(LIST *l, ElemType x)
{
int count=0;
NODE *p = l->front;
while(p!=NULL)
{
if(p->val == x)
count++;
p = p->next;
}
return count;
}