c. [20 marks] Complete the function reverse(L) which adjusts L so that its nodes
ID: 3916128 • Letter: C
Question
c. [20 marks] Complete the function reverse(L) which adjusts L so that its nodes are in the reverse sequence than when it started. You will write an iterative version for the full 20 marks. But if you read or write the data field of any node, you will receive 0 marks. Put another way: your algorithm may only adjust the pointers in the nodes, but never the values If you feel ambitious, you can submit an additional version which uses recursion (and no loops) for 5 [additional] bonus marks. Again, write "BONUS" to make the distinction clear to the markers d. // Post: L contains the data in the original L, but in the reverse order. void reverse(Llt* Reversed version of sample: reverse (L): head: 36 143 361 ? 42 NULL tail:Explanation / Answer
void reverse(LL_t *current)
{
LL_t *prev = NULL, *next = NULL;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
head = prev;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.