Skip to content
This repository has been archived by the owner on Nov 26, 2019. It is now read-only.

Latest commit

 

History

History

reverse_linkedlist_using_stack

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Reversing a Linked List using Stack

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.

Input Format

We need to enter the data for each node of the list

Output Format

The linked list will be reversed and the contents of the modified list will be displayed.

Sample Input

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

Sample Output

The linked list created is: 7 2 1 5 3
The linked list after reversing is: 3 5 1 2 7

Implemented in: