Reverse Print List

Posted by Sherlock Blaze on 2019-01-24

Question

There is a single linkedlist that prints out the values of each node from end to head.

Thought

I don’t think it’s a difficult problem, we just need use a stack, store the values and print them.
We do like this:

We got a list and a stack.

Step1

We push the values of list into the stack one by one.

Step2

And we already know about how stack works. If you don’t know about it clearly, go here to read more.

Step3

At the last, we can get result by popping the elements from the stack.

Step4

Code

We use the linkedlist and stack implemented before to implement it. Just read the code:

1
Waiting...