# Print a Linked List in Reverse Order using Recursion

• Write a C program to read a linked list in reverse direction using recursion.

To print a singly linked list in reverse order, we will use a recursive function.
We will store the head node of linked list in function stack and then recursively call reverseLLPrint function for sub linked list starting from head->next. When sub linked list get printed in reverse order then we will print the head node stored in function stack.

```Input Linked List
1 --> 8 --> 3 --> 20 --> 5 --> NULL
Nodes in reverse order
5 20 3 8 1
```
Singly linked list's node structure is as follows:
```struct node {
int data;
struct node *next;
}
```
Function void reverseLLPrint(struct node *head) is a recursive function which takes head pointer of a linked list prints it's nodes in reverse order.
```void reverseLLPrint(struct node *head) {
}
}
```

## C program to print a linked list in reverse using recursion

```#include <stdio.h>
#include <stdlib.h>

/* A structure of linked list node */
struct node {
int data;
struct node *next;

void initialize(){
}

/*
Given a Inserts a node in front of a singly linked list.
*/
void insert(int num) {
/* Create a new Linked List node */
struct node* newNode = (struct node*) malloc(sizeof(struct node));
newNode->data  = num;
/* Next pointer of new node will point to head node of linked list  */
printf("Inserted Element : %d\n", num);
}

/*
Prints Linked List in reverse order without reversing it.
*/
}
}

/*
*/
while (nodePtr != NULL) {
printf("%d", nodePtr->data);
nodePtr = nodePtr->next;
if(nodePtr != NULL)
printf("-->");
else
printf("-->NULL");
}
}

int main() {
initialize();
insert(8);
insert(3);
insert(2);
insert(7);
insert(9);

printf("\nPrinting Linked List in Reversed Order\n");

return 0;
}
```
Output
```Inserted Element : 8
Inserted Element : 3
Inserted Element : 2
Inserted Element : 7
Inserted Element : 9

9-->7-->2-->3-->8-->NULL
Printing Linked List in Reversed Order
8 3 2 7 9
```