Reversing Linked List - C++

前端 未结 3 1087
既然无缘
既然无缘 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:18

    Everyone must have the same homework assignment today.

    I think it would be more helpful to these people to show them what happens to the state of the list while it is being reversed. This should help them better than showing them code or code problems.

    Here is what should happen (with the algorithm I would use)

    [] = head () = current

    ([1])->2->3->4, [2]->(1)->3->4, [3]->2->(1)->4, [4]->3->2->(1) done because current now doesn't have a new next

提交回复
热议问题