m_f@midwest.socialM to Fun Loops ▶️@midwest.socialEnglish · 1 day ago[R] Stupidest ways people have solved coding interviewsloops.videoexternal-linkmessage-square34fedilinkarrow-up177arrow-down15
arrow-up172arrow-down1external-link[R] Stupidest ways people have solved coding interviewsloops.videom_f@midwest.socialM to Fun Loops ▶️@midwest.socialEnglish · 1 day agomessage-square34fedilink
minus-squareScreamingFirehawklinkfedilinkarrow-up15·1 day agoIt doesn’t, the array is still in the same order it started in, it’s members are just printed to the console in numerical order. It just prints the number 1 after 1 ms, 2 after 2 ms, 3 after 3 ms etc.
minus-squareRandelung@lemmy.worldlinkfedilinkarrow-up7·1 day agoInstead of print you could add them to a second array, though. Even clear the original first for “in place” sorting; never mind the memory allocation for the lambdas.
minus-squareMaalus@lemmy.worldlinkfedilinkarrow-up2·1 day agoAlso since you aren’t guaranteed that there is a “happens before” relationship, it’s a wrong implementation that returns unsorted arrays in text too.
It doesn’t, the array is still in the same order it started in, it’s members are just printed to the console in numerical order.
It just prints the number 1 after 1 ms, 2 after 2 ms, 3 after 3 ms etc.
Instead of print you could add them to a second array, though. Even clear the original first for “in place” sorting; never mind the memory allocation for the lambdas.
Also since you aren’t guaranteed that there is a “happens before” relationship, it’s a wrong implementation that returns unsorted arrays in text too.