[PR #884] [CLOSED] reverse a linked list #1401

Open
opened 2026-01-29 15:20:11 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/TheAlgorithms/C/pull/884
Author: @vedic-kalra
Created: 10/13/2021
Status: Closed

Base: masterHead: master


📝 Commits (1)

📊 Changes

1 file changed (+68 additions, -0 deletions)

View changed files

data_structures/linked_list/reverse_a_linked_list.c (+68 -0)

📄 Description

Description of Change

Step 1- Initialize three pointers prev as NULL, curr as head and next as NULL.
Step 2-Iterate through the linked list. In loop, do following.
Before changing next of current,
store next node
next = curr->next
Now change next of current
This is where actual reversing happens
curr->next = prev
Move prev and curr one step forward
prev = curr
curr = next

References

Solution to issue #870

Checklist

Notes:
This is an iterative approach to reverse a linked list.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/TheAlgorithms/C/pull/884 **Author:** [@vedic-kalra](https://github.com/vedic-kalra) **Created:** 10/13/2021 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`39e1467`](https://github.com/TheAlgorithms/C/commit/39e14673769a1c1c576c6d8bf05b59edf1b09d97) reverse a linked list ### 📊 Changes **1 file changed** (+68 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `data_structures/linked_list/reverse_a_linked_list.c` (+68 -0) </details> ### 📄 Description #### Description of Change <!-- Thank you for your Pull Request. Please provide a description above and review the requirements below. Contributors guide: https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md --> Step 1- Initialize three pointers prev as NULL, curr as head and next as NULL. Step 2-Iterate through the linked list. In loop, do following. Before changing next of current, store next node next = curr->next Now change next of current This is where actual reversing happens curr->next = prev Move prev and curr one step forward prev = curr curr = next #### References <!-- Add any reference to previous pull-request or issue --> Solution to issue #870 #### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [x ] Added description of change - [x ] Added file name matches [File name guidelines](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#File-Name-guidelines) - [x ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#Commit-Guidelines) Notes: <!-- Please add a one-line description for developers or pull request viewers --> This is an iterative approach to reverse a linked list. <a href="https://gitpod.io/#https://github.com/TheAlgorithms/C/pull/884"><img src="https://gitpod.io/button/open-in-gitpod.svg"/></a> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 15:20:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#1401