When you use
You are not making array2 a true copy of array1, you are making an alias, both array1 and array2 point to the same object. That means when you sort array1 then array2 is also sorted now!
To make a true copy of a simple list you can use
There are a lot of strange things in your code, is this a direct translation from C?