Problem 4 [40 marks] Complete the following three linked list functions accordin
ID: 3915157 • Letter: P
Question
Problem 4 [40 marks] Complete the following three linked list functions according to the provided specifications. Use full C code (must be able to compile and with detail comments) In all cases, you should assume that a linked list data type is composed of two fields, a pointer to the head node, a pointer to the tail node, but both NULL if empty. Each node contains two fields: its value data and a pointer to the next node in the chain. Assume al linked lists and node sequences are valid. Another Warning: The code for these are probably searchable on the intemet somewhere. While getting someone else to solve a problem for you might be acceptable practice in the workplace, it is not here. The point of the exercises are for you to get some practice at these sorts of tasks, which might just make you better. It might also be of benefit for you on exams where internet access tends to be somewhat. ..limited The sample input list L: head: 42 36 14 17 48 36 NULL tail: a. [10 marks] Complete the function freq(L, x) which returns the number of times that datum x appears in linked list L. You may use a loop or recursion: it's up to you.Explanation / Answer
//frequency of numbers
unsigned int freq(LL_t *L,int x){
LL_t*temp=L->head;
unsigned int count=0;
while(temp!=NULL){
if(temp->data==x)count++;
temp=temp->next;
}
return count;
}
//print linklist
void print(LL_t*L){
LL_t*temp=L->head;
while(temp!=NULL){
printf("%d ",temp->data);
temp=temp->next;
}
}
//reverse linklist;
void reverse(LL_t*L){
L->tail=L->head;
LL_t *current = L->head;
LL_t *prev = NULL, *next = NULL;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
L->head = prev;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.