Thank you for your comment and interesting observation!
While the precedence order that mentioned is correct to the vast majority of programming languages, it is not the case for Go:
There are five precedence levels for binary operators. Multiplication operators bind strongest, followed by addition operators, comparison operators, && (logical AND), and finally || (logical OR):
Hey sashagil!
Thank you for your comment and interesting observation!
While the precedence order that mentioned is correct to the vast majority of programming languages, it is not the case for Go:
The quote above is from Golang spec.
We can verify it in playground:
Уже не раз было отмечено - пренебрежимое старение это не фича, а баг эволюции.
Очень интересное наблюдение, а где можно подробнее про это увидеть?
Thanks, fixed!
Thanks, got it.
Let me check if I got the idea.
Let's say we have
[1, 2, 1, 0]
In the first pass, we count the number of occurrences for
zeroes
,ones
andtwos
:0:0, 1:2, 2:1
And in the second run, we restore the array. Did I get the idea?
If I understood you correctly, then the described algorithm does not work in-place, right?
EDIT: I noted that my post doesn't emphasize that the provided solution works in-place. Thanks for the remark, updated the article.