15 1
15 1
CODE:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
newNode->next = NULL;
return newNode;
current = current->next;
printf("NULL\n");
next = current->next;
current->next = prev;
prev = current;
current = next;
return prev;
next = current->next;
free(current);
current = next;
int main() {
head->next = createNode(2);
head->next->next = createNode(3);
head->next->next->next = createNode(4);
head->next->next->next->next = createNode(5);
printList(head);
head = reverseList(head);
printList(head);
freeList(head);
return 0;
OUTPUT:
ALGORITHM:
Step 1:start
Step 2:Initialization:
prev (set to NULL), current (set to the head of the list), and next (initially uninitialized).
After the loop, prev will be pointing to the new head of the reversed list. Return prev.
TRACING: