Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Reversing Linked List Data Structure | DSA Tutorials

YASH PAL, 12 May 20204 May 2026

Reversing Linked List – Reversing a linked list means changing the link part of all nodes of a linked list to point to the nodes that come before every node.

Reversing a linked list
Figure 1: Reversing a linked list

As you see, we have a linked list that has four nodes, and to reverse this list, we need to point every node’s linked part to the node that comes right before it. And in the end, we update the start variable’s position to the last node of the list, as you see in Figure 2.

Reversing a linked list
Figure 2: Reversing a linked list

Reverse a linked list using the links of nodes

To reverse a linked list using the links of nodes, we need three references: prev, p, and next. In the beginning, we set the prev variable to None and set the reference of the first node of the linked list to variable p.

Reverse a linked list using the links of nodes
Figure 3: Reverse a linked list using the links of nodes

And then we start a loop till the value p becomes None. means till we don’t reach the last node of the list. In every iteration, we set the reference of the node that comes after node p into the variable next.

Reverse a linked list using the links of nodes

And then we set the linked part of node p equal to the prev variable.

Reversing a linked list

After that, we store the reference of node p into the variable prev. So now the variable prev points to the node that points to variable p.

Reversing a linked list

And then we change the reference of node p using the variable next, which means now the variable p points to the node that points to the variable next.

Reversing a linked list

Now, these conditions will run until we reach the end of the list.

Reversing a linked list
Reversing a linked list
Reversing a linked list
Reversing a linked list
Reversing a linked list
Reversing a linked list
Reversing a linked list
Reversing a linked list
Reversing a linked list

Now we have reached the end of the list because the linked part of node p is None. So now we update the self-variable value and point to the last node of the list.

Reversing a linked list

So Now the linked list is reversed using the links of every node. 

Here is the Python code to reverse a linked list using the links of every node.

def reverse_list(self):
    prev = None    p = self.start
    while p is not None:
        next = p.link
        p.link = prev
        prev = p
        p = next
    self.start = prev

Data Structures & Algorithms Tutorials for Beginners
Computer Science Tutorials Data Structures Tutorials computer scienceData StructureDSA Tutorials

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes