-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray.go
More file actions
41 lines (32 loc) · 751 Bytes
/
array.go
File metadata and controls
41 lines (32 loc) · 751 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package BDS
import "fmt"
type Array struct {
Value []interface{} `json:"value"`
LengthValue int `json:"length"`
}
// creat Array struct.
func NewArray(num int) *Array {
result := make([]interface{}, num)
return &Array{
Value: make([]interface{}, num),
LengthValue: len(result),
}
}
// pop a data.
func (a *Array) Pop(data interface{}) {
a.Value = append(a.Value, data)
}
// pubsh a data.
func (a *Array) Push() (d interface{}, err error) {
if a.Length() <= 0 {
return nil, fmt.Errorf("error:cant push data,length is 0")
} else {
d = a.Value[len(a.Value)-1]
a.Value = a.Value[:a.Length()-1]
}
return
}
// return array's real length by len(value).
func (a *Array) Length() int {
return len(a.Value)
}