-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path225.go
46 lines (39 loc) · 771 Bytes
/
225.go
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
43
44
45
46
package main
type MyStack struct {
list []int
top int
}
func Constructor() MyStack {
return MyStack{list: make([]int, 10)}
}
func (this *MyStack) Push(x int) {
this.list = append(this.list, x)
this.top = x
}
func (this *MyStack) Pop() int {
if !this.Empty() {
this.list = this.list[:len(this.list)-1]
pop := this.top
if len(this.list) != 0 {
this.top = this.list[len(this.list)-1]
} else {
this.top = 0
}
return pop
}
return 0
}
func (this *MyStack) Top() int {
return this.top
}
func (this *MyStack) Empty() bool {
return len(this.list) == 0
}
/**
* Your MyStack object will be instantiated and called as such:
* obj := Constructor();
* obj.Push(x);
* param_2 := obj.Pop();
* param_3 := obj.Top();
* param_4 := obj.Empty();
*/