-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (34 loc) · 834 Bytes
/
main.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
package main
type MyQueue struct {
stack1 []int
}
/** Initialize your data structure here. */
func Constructor() MyQueue {
return MyQueue{}
}
/** Push element x to the back of queue. */
func (this *MyQueue) Push(x int) {
this.stack1 = append(this.stack1, x)
}
/** Removes the element from in front of queue and returns that element. */
func (this *MyQueue) Pop() int {
v := this.stack1[0]
this.stack1 = this.stack1[1:]
return v
}
/** Get the front element. */
func (this *MyQueue) Peek() int {
return this.stack1[0]
}
/** Returns whether the queue is empty. */
func (this *MyQueue) Empty() bool {
return len(this.stack1) == 0
}
/**
* Your MyQueue object will be instantiated and called as such:
* obj := Constructor();
* obj.Push(x);
* param_2 := obj.Pop();
* param_3 := obj.Peek();
* param_4 := obj.Empty();
*/