Core JavaNo Comments

default thumbnail

Write a sample code to reverse Singly Linked List by iterating through it only once.

Recursive Method:
1) Divide the list in two parts – first node and rest of the linked list.
2) Call reverse for the rest of the linked list.
3) Link rest to first.
4) Fix head pointer.


Adding: 3
Adding: 32
Adding: 54
Adding: 89

3 32 54 89

reversing the linked list

89 54 32 3

Be the first to post a comment.

Add a comment