Linked Lists are linear data structure just like arrays but unlike arrays where the data is kept in contiguos locations,in linked list the data is not contiguos.It basically consists of nodes and each node contains data and the address to the next node in the list. Reversing a linked list means the the first node of the list will be moved to the last,the second node to the last second position and so on. Here reversing is implemented with the help of a stack.
We need to enter the data for each node of the list
The linked list will be reversed and the contents of the modified list will be displayed.
Enter the data for node 1: 3
Enter the data for node 2: 5
Enter the data for node 3: 1
Enter the data for node 4: 2
Enter the data for node 5: 7
The linked list created is: 7 2 1 5 3
The linked list after reversing is: 3 5 1 2 7