Spread the post

Print reverse linked list node data

Suppose linked list contain following nodes[45 235 63 21 52 51 23 66 21]. Our goal is print data reverse data [21 66 23 51 52 21 63 235 45].

root_ptr2166235152216323545

Try it Yourself

View nodes.

Global Variableroot(pointer) Stack Areamainshow_datatemp(pointer) Heap Areastruct Nodedata (int)= 45next (pointer) struct Nodedata (int)= 235next (pointer) struct Nodedata (int)= 63next (pointer) struct Nodedata (int)= 21next (pointer) struct Nodedata (int)= 52next (pointer) struct Nodedata (int)= 51next (pointer) struct Nodedata (int)= 23next (pointer) struct Nodedata (int)= 66next (pointer) struct Nodedata (int)= 21next (pointer)= NULL

Try it Yourself

Time complexity of this program O(n)

Below in C implementation of this problem. Recursive approach.

Accepted Output

Given list is : 45 235 63 21 52 51 23 66 21

Print reverse data is : 21 66 23 51 52 21 63 235 45

Output

Spread the post

Recommended Posts: