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

Copy the values you have in a single linked list into a double linked list backw

ID: 673380 • Letter: C

Question

Copy the values you have in a single linked list into a double linked list backwards. In other words, the value in the last node of the single linked list will be the value in the first node in the double linked list, and so on. Write the program . Copy the values you have in a single linked list into a double linked list backwards. In other words, the value in the last node of the single linked list will be the value in the first node in the double linked list, and so on. Write the program . Write the program .

Explanation / Answer

#include typedef struct Node { char data; struct Node* next; } Node; void print_list(Node* root) { while (root) { printf("%c ", root->data); root = root->next; } printf(" "); } Node* reverse(Node* root) { Node* new_root = 0; while (root) { Node* next = root->next; root->next = new_root; new_root = root; root = next; } return new_root; } int main() { Node d = { 'd', 0 }; Node c = { 'c', &d }; Node b = { 'b', &c }; Node a = { 'a', &b }; Node* root = &a; print_list(root); root = reverse(root); print_list(root); return 0; }