What does the following functions do? int mystry(struct node* head) { int count
ID: 3874599 • Letter: W
Question
What does the following functions do? int mystry(struct node* head) { int count - 0 struct node*current - head; while (current != NULL) { count++ current = current->next return (count); struct node* mystry (struct node* head) { struct node* a - head; struct node* bNULL; struct node* tail-NULL while (a != NULL) { if (b == NULL) { b = malloc ( sizeof ( struct b->data = a->data; b-> next NULL ; tail = b; node ) ) ; } else t tail->next = malloc ( sizeof ( struct node ) ) ; tail - tail->next; tail->data = a->data; tail->next = NULL ; a a->next; = } return(b);Explanation / Answer
a.) Lets say node represent an element of a linked list.
In this part the mystry function will calculate the length of the linked list,i.e.,the number of elements present in the linked list.
After calculating length of the linked list it will return its value.
b.) Lets say node represent an element of a linked list.
This function will initialize a linked list (say L) having node head and tail initialized to null.
Then it will make a copy of the linked list whose pointer to its first element has been passed as argument to this function into linked list L ,i.e., this function will copy the elements of a linked list whose pointer to its first element has been passed as argument to this function into another linked list L.
After that it will return the pointer to the first element of the linked list L.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.