Problem solving with programming: Splitting the linked list into two halves
Given a single linked list, how do we split it into two halves.
For example the list 1->2->3->4 should be divided into 1->2 and 3->4
If the length of the list is odd, add the extra node to first half; so 1->2->3 should be split to 1->2 and 3.
This problem can be efficiently solved using fast pointer, slow pointer mechanism explained in this post.
Read full article from Problem solving with programming: Splitting the linked list into two halves
No comments:
Post a Comment