Hello , I am trying to learn data structures and algorithms. I am reading about Linked List and was trying to solve some challenges from leetcode. One of them is to sort a linked list Sort a linked list in O(n log n) time using constant space complexity.
Example 1:
Input: 4->2->1->3
Output: 1->2->3->4
Example 2:
Input: -1->5->3->4->0
Output: -1->0->3->4->5
Following is my implementation :
While running the code I am getting the following error : java.lang.StackOverFlowError at line 19
I am not able to figure out what I am doing wrong here.
I tried to implement the challenge in my
IDE and it seems to work fine. Here is my code :
Node Class
LinkedList class
TestClass
Output: