Partition Linked List around a Value X

How do you partition a list around a value x, such that all nodes less than x come before all nodes greater than or equal to x?

Well, there are some solutions possible. The solution, I came up with, is a bit convoluted but let me tell the idea behind it. You want to track the following:

Now that we have this out of the way, let’s look at the code:

Code

As usual the code is available here:

https://github.com/abhi1010/Algorithms

comments powered by Disqus