Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Hackerrank/reverse-a-linked-list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*approach :
We create three pointers to traverse the current previous and the next node, and with each current node, we modify its next pointer and update the pointer again*/


#include <bits/stdc++.h>
using namespace std;
SinglyLinkedListNode* reverse(SinglyLinkedListNode* llist) {
if(!llist) return llist;

SinglyLinkedListNode* prev = nullptr;
SinglyLinkedListNode* curr = llist;
SinglyLinkedListNode* next = nullptr;

while(curr){
next = curr->next;
curr->next = prev;

prev = curr;
curr = next;
}

return prev;
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ In this repository, you can find the solutions (as source code) for the problems
| [Nauman Chaudhary](https://github.com/nauman-chaudhary) <br> <img src="https://github.com/nauman-chaudhary.png" width="100" height="100"> | Pakistan | Python | |
| [Gourav Rusiya](https://github.com/GouravRusiya30) <br> <img src="https://github.com/GouravRusiya30.png" width="100" height="100"> | India | Java | https://www.hackerrank.com/gouravrusiya786 |
| [Trushita Maurya](https://github.com/trushita23) <br> <img src="https://github.com/trushita23.png" width="100" height="100"> | India | Java

| [Arjun Chaudhary](https://github.com/Arjun-3105) <br> <img src="https://github.com/Arjun-3105.png" width="100" height="100"> |
India | C++
### License

[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://github.com/ows-ali/Hacktoberfest/blob/master/LICENSE)