-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraystack.go
More file actions
42 lines (35 loc) · 715 Bytes
/
Copy patharraystack.go
File metadata and controls
42 lines (35 loc) · 715 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
42
package arraylists
type Element struct {
Value interface{}
List *ArrayStack
}
type ArrayStack struct {
array []*Element
}
func NewArrayStack() *ArrayStack {
a := &ArrayStack{}
a.array = make([]*Element, 0, 10)
return a
}
func (a *ArrayStack) Push(value interface{}) (e *Element) {
e = &Element{Value:value, List:a}
a.array = append(a.array, e)
return e
}
func (a *ArrayStack) Pop() (e *Element) {
if a.Len() > 0 {
e = a.array[len(a.array)-1]
a.array = a.array[:len(a.array)-1]
return e
}
return e
}
func (a *ArrayStack) Remove() (e *Element) {
if a.Len() >0 {
e = a.array[0]
a.array= a.array[1:len(a.array)]
return
}
return
}
func (a ArrayStack) Len() int { return len(a.array) }