1/25/2024
Relative sort array #2 attempt
This is my second attempt for the Relative sort array problem.
Some lessons I learn this time:
Whenever you create a loop, make sure that it stops. At first, I put curP++
in the if block. As a result, curP only move to the next element when there is at least one other element in the rest of the array arr1 that is smaller than the element it points to. If curP points to the smallest element, the if block will never be executed, and thus, curP
never reaches the end of the array.
It turns out that in selection sort, we check each element and then move on. We don't need to swap all element, only the elements that are at the wrong place in a sorted array.