支持复制切片

This commit is contained in:
kercylan98 2023-05-12 18:07:26 +08:00
parent b61a76ee6c
commit 9a1e63193e
1 changed files with 9 additions and 0 deletions

View File

@ -11,6 +11,15 @@ func Del[V any](slice *[]V, index int) {
*slice = append(s[:index], s[index+1:]...)
}
// Copy 复制特定切片
func Copy[V any](slice []V) []V {
var s = make([]V, len(slice), len(slice))
for i := 0; i < len(slice); i++ {
s[i] = slice[i]
}
return s
}
// Insert 在特定索引插入元素
func Insert[V any](slice *[]V, index int, value V) {
s := *slice