Comment

Comment by BoppreH

Not quite, your algorithm has j going from i+1 to n, and swapping when a[i] > a[j].

OP's algorithm has both indexes going from 1 to n, and swapping when a[i] < a[j].

Yours is more efficient and easy to see why it's correct, but OP's is slightly simpler and more surprising.

parent BoppreH 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton