Create a reverse LinkedList in C++ from a given LinkedList

前端 未结 10 984
温柔的废话
温柔的废话 2020-11-30 08:37

I\'m having some trouble create a linkedlist in reverse order from a given linkedlist.

I come from a java background, and just started doing some C++.

Can yo

10条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 08:44

    Another method would be to first traverse the list and store all data in a stack,then create a new list and insert data in it from top of the stack.Stack being LIFO will give you the data in reverse order and hence you will have a reversed list.

提交回复
热议问题