Challenge: Reverse a Linked List

Can we implement a program which could reverse a linked list? Let's find out.

Problem Statement

You have to define the reverse function, which takes a singly linked list and produces the exact opposite list, i.e., the links of the output linked list should be reversed.

Input

A singly linked list.

Output

The reversed linked list.

Sample Input

The input linked list object:

LinkedList = 0->1->2->3-4

Sample Output

The reversed linked list:

LinkedList = 4->3->2->1->0

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy