Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:48:40+00:00 2026-05-30T22:48:40+00:00

How can we reverse a linked list if it has a loop (ie if

  • 0

How can we reverse a linked list if it has a loop (ie if the last node is is linked to a node in the middle) ?

Well, I saw that one of the solutions in here and hereto detect a loop in a linked list is to reverse it.
My doubt is – how is it possible to reverse a linked list,if you do not know where it ends. How can one even reverse a linked list that has a loop ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:48:41+00:00Added an answer on May 30, 2026 at 10:48 pm

    Well, first, you’re going to need to define what “reverse” means in this context. Probably, what you need to do is

    (1) find the link that makes it cyclic

    (2) break that link

    (3) then reverse the list somehow.

    Doing it efficiently is going to mean finding some efficient way to identify the cycle. But if we assume a stack with an operation to tell if a node is already there, then you can just push the nodes onto a stack, checking until you give a link to a node you’ve already seen. Then pop the stack and voila you have the list in reverse order.

    in pseudocode, you need a stack with an isIn operation

       stack:
         init()
         push(node)
         pop() returns node
         isIn(node) returns Boolean
    

    and do something like

     do
        get next node
        if node isIn stack
        then
           while stack not empty
               pop node
           break
        else
           push node in stack
        fi
     od
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One method which I can think of is to reverse the list and then
This article says that Emacs has redo because you can reverse direction while undoing,
Are there any command line scripts and/or online tools that can reverse the effects
I need an algorithm that can do a one-to-one mapping (ie. no collision) of
I am writing a Java function to reverse a linked list in-place. I am
Can't seem to work out why I'm getting garbage output from this Linked List
I know that we can reverse engineers sites definitions and other sharepoint moss entities
I am looking for a software that can reverse engineering a delphi 2010 project
The task is to reverse a linked list, so I build the linked list,
I am trying to sort a singly linked list which has been created and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.