Reversing Linked List - C++

前端 未结 3 1110
既然无缘
既然无缘 2021-01-17 02:05

I wrote a function that should reverse a list.

So far, I can reverse only two items, but no more. I checked and double checked and still can\'t find the problem. I e

3条回答
  •  感情败类
    2021-01-17 02:20

    Sorry for answering late and I am sure that you would have found the answer by now but yet it might be helpful for others. Answer is simply taking return statement (i.e. return head;) out of while loop will fix your problem. Though there are ways you can avoid extra pointer and assignments to optimise your code.

提交回复
热议问题