i new golang, although have written lines of code. exploring sorting options when found this(src):
func (p stringslice) swap(i, j int) { p[i], p[j] = p[j], p[i] } i have no clue going on there. explain me p[i], p[j] = p[j], p[i] doing?
thanks.
it name says: swaps ith , jth elements.
it assignment, more tuple assignment:
p[i], p[j] = p[j], p[i] it assigns values p[i] , p[j], , values assigned them in order p[j] , p[i].
the assignment proceeds in 2 phases. first, operands of index expressions , pointer indirections (including implicit pointer indirections in selectors) on left , expressions on right evaluated in usual order. second, assignments carried out in left-to-right order.
Comments
Post a Comment