Is it possible to reverse a linked list that contains a cycle?

I'm looking at some interview questions, and one of them asks to reverse a linked list that contains a cycle. So suppose I had a linked list like the following:

          F <- E
          |    /\
          V    |
A -> B -> C -> D 

Then reversing the list would create the following:

          F -> E
         /\    |
          |    V
A <- B <- C <- D

The problem here is that there's a conflict between which nodes C should be pointing at. So would we just eliminate the link between C and F?

8
задан templatetypedef 16 February 2012 в 20:22
поделиться