Reverse a linked list using 2 pointers technique using XOR operator

You must have come across reversing a linked list using 3 pointers technique which is the most common approach to do it. But do you know how to reverse a linked list with just 2 pointers? This article will teach you just that! Let's dive into it.


Introduction

Let us consider the following input :

(^ represents the head pointer to the list)


Input :

1 -> 2 -> 3 -> 4 -> 5

^

Our objective is to reverse the linked list by reversing its links


Expected Output :

1
..............................^


Befor...

 •  0 comments  •  flag
Share on Twitter
Published on May 23, 2020 06:10
No comments have been added yet.