mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-04 05:44:35 +00:00
[PR #884] [CLOSED] reverse a linked list #1401
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/TheAlgorithms/C/pull/884
Author: @vedic-kalra
Created: 10/13/2021
Status: ❌ Closed
Base:
master← Head:master📝 Commits (1)
39e1467reverse a linked list📊 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.