Исходники и презентации
This commit is contained in:
19
lessons/slices_and_arrays/copy_implementation/main.go
Normal file
19
lessons/slices_and_arrays/copy_implementation/main.go
Normal file
@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func cp(dst, src []int) {
|
||||
minLength := min(len(dst), len(src))
|
||||
for idx := 0; idx < minLength; idx++ {
|
||||
dst[idx] = src[idx]
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
src := []int{1, 2, 3, 4, 5}
|
||||
dst := make([]int, 3)
|
||||
copy(dst, src)
|
||||
|
||||
fmt.Println("src", src)
|
||||
fmt.Println("dst", dst)
|
||||
}
|
||||
Reference in New Issue
Block a user