Anonymous user
Filter: Difference between revisions
→{{header|Go}}: using vector is more efficient than repeatedly using append. append re-allocates a new array each time (O(n)). vector has amortized O(1) push
(→{{header|Go}}: using vector is more efficient than repeatedly using append. append re-allocates a new array each time (O(n)). vector has amortized O(1) push) |
|||
Line 399:
"fmt"
"rand"
"container/vector"
)
Line 407 ⟶ 408:
}
func even(a []int)
r := new(vector.IntVector)
for _, e := range a {
if e%2 == 0 {
r
}
}
return *r
}</lang>
Output:
|