-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconstructors.go
More file actions
27 lines (24 loc) · 852 Bytes
/
constructors.go
File metadata and controls
27 lines (24 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package govector
//Init : returns a copy of a initialized vector.
// _Notes:
// you should set the vecotr equal to the result of it initializing since it returns a copy
// EX. "v = v.Init()" is correct usage of this
// _Return:
// a initialized vector.
func (v *Vector) Init() Vector {
copyVect := Vector{data: make([]T, 0), size: 0}
return copyVect
}
//InitWithSlice : returns a copy of a initialized vector that turns the slice into a vector
//_Parameters:
// elems: T "The slice you want to convert into a vector"
// _Return:
// a initialized vector.
func (v *Vector) InitWithSlice(elems []T) Vector {
//it will pull a syntax error if tried to directly initialize through Init()
var vectClone = Vector{data: make([]T, 0), size: 0}
for index := 0; index < len(elems); index++ {
vectClone.PushBack(elems[index])
}
return vectClone
}