Skip to content

Reverse a linked List – Iterative Solution  #2641

@meenachan

Description

@meenachan

Is your feature request related to a problem? Please describe.
Given pointer to the head node of a linked list, the task is to reverse the linked list. We need to reverse the list by changing the links between nodes.

Describe the solution you'd like
Iterative Method

  1. Initialize three pointers prev as NULL, curr as head and next as NULL.
  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

Additional context
Please assign this to me

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions