Pull to refresh
10
0
Aynur Zulkarnaev @aydu

User

Send message

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:


There are five precedence levels for binary operators. Multiplication operators bind strongest, followed by addition operators, comparison operators, && (logical AND), and finally || (logical OR):

    5             *  /  %  <<  >>  &  &^
    4             +  -  |  ^
    3             ==  !=  <  <=  >  >=
    2             &&
    1             ||

The quote above is from Golang spec.


We can verify it in playground:


v := 1<<63 — 1
v1 := (1 << 63) — 1
fmt.Println(v == v1) // true

Уже не раз было отмечено - пренебрежимое старение это не фича, а баг эволюции. 

Очень интересное наблюдение, а где можно подробнее про это увидеть?

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 and twos:


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.

Thank you for the feedback!

Information

Rating
Does not participate
Registered
Activity