C Program to reverse each node value in Singly Linked List Last Updated : 15 Sep, 2022 Comments Improve Suggest changes Like Article Like Report A linked list is a linear collection of data elements, in which each node points to the next node. Unlike an array, it doesn't have upper limit and hence extremely useful. The task is to access value of each node of linked list and reverse them. Examples: Input : 56 87 12 49 35 Output : 65 78 21 94 53 Input : 128 87 12433 491 33 Output : 821 78 33421 194 33 Algorithm: The task can be accomplished as: Linearly traverse each node of the singly linked list.Reverse the value of each node.Store the reversed value in the current node. Implementation: C // C program to reverse every node data in // singly linked list. #include <stdio.h> #include <stdlib.h> // A linked list node struct Node { int data; struct Node* next; }; // newNode function inserts the new node at // the right side of linked list struct Node* newNode(int key) { struct Node* temp = (struct Node*)malloc(sizeof(struct Node)); temp->data = key; temp->next = NULL; return temp; } // reverse() will receive individual data item // from reverseIndividualData() and will return // the reversed number to calling function int reverse(int number) { int new_num = 0, rem; while (number != 0) { rem = number % 10; new_num = new_num * 10 + rem; number = number / 10; } return new_num; } void reverseIndividualData(struct Node* node) { if (node == NULL) return; while (node != NULL) { /* function call to reverse(), reverseIndividualData(struct Node *node) will send the one data item at a time to reverse(node->data) function which will return updated value to node->data*/ node->data = reverse(node->data); /* updating node pointer so as to get next value */ node = node->next; } } // Function to print nodes in linked list void printList(struct Node* node) { while (node != NULL) { printf("%d ", node->data); node = node->next; } } // Driver program to test above functions int main() { struct Node* head = NULL; head = newNode(56); head->next = newNode(87); head->next->next = newNode(12); head->next->next->next = newNode(49); head->next->next->next->next = newNode(35); printf( "\nList before reversing individual data item \n"); printList(head); reverseIndividualData(head); printf("\nList after reversing individual data item\n"); printList(head); return 0; } Output List before reversing individual data item 56 87 12 49 35 List after reversing individual data item 65 78 21 94 53 Comment More infoAdvertise with us Next Article C Program to reverse each node value in Singly Linked List A AmishTandon Follow Improve Article Tags : Misc Linked List DSA Reverse Practice Tags : Linked ListMiscReverse Similar Reads Reverse each word in a linked list node Given a linked list of strings, we need to reverse each word of the string in the given linked list. Examples: Input: geeksforgeeks a computer science portal for geeks Output: skeegrofskeeg a retupmoc ecneics latrop rof skeeg Input: Publish your own articles on geeksforgeeks Output: hsilbuP ruoy nwo 6 min read Reverse alternate K nodes in a Singly Linked List Given a linked list, The task is to reverse alternate k nodes. If the number of nodes left at the end of the list is fewer than k, reverse these remaining nodes or leave them in their original order, depending on the alternation pattern.Example: Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 15+ min read Javascript Program For Reversing Alternate K Nodes In A Singly Linked List Given a linked list, write a function to reverse every alternate k nodes (where k is an input to the function) in an efficient way. Give the complexity of your algorithm.Example: Inputs: 1->2->3->4->5->6->7->8->9->NULL and k = 3Output: 3->2->1->4->5->6->9 5 min read Reverse alternate K nodes in a Singly Linked List - Iterative Solution Given a linked list and an integer K, the task is to reverse every alternate K nodes.Examples: Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> NULL, K = 3 Output: 3 2 1 4 5 6 9 8 7Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> NULL, K = 12 min read Reverse a Doubly Linked List without swapping nodes Write a program to reverse the given Doubly Linked List. See below diagrams for example. (a) Original Doubly Linked List (b) Reversed Doubly Linked List Approach: In the previous post, doubly linked list is being reversed by swapping prev and next pointers for all nodes, changing prev of the head (o 10 min read Like