My concern is that you allocate as many arrays, as you have elements in your original array. It's can be quite wasteful if high performance is a goal.

To implement the algorithm efficiently, you just need one additional array.