Re:Data structures and algorithms problems in C++ using STL
by pklausler on Friday March 10, 2017 @03:01PM
(#13841593)
> 2) Given an array of zeroes and ones, sort it stably using O(n) time and O(1) extra space.
I'm missing something here. If the array's values truly are all in {0,1}, then all the zeroes are indistinguishable and you get stability for free (same for the ones).
mysort all01list = let ones = sum all01list in replicate (length all01list - ones) 0 ++ replicate ones 1
I'm missing something here. If the array's values truly are all in {0,1}, then all the zeroes are indistinguishable and you get stability for free (same for the ones).