-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (77 loc) · 1.6 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import "container/list"
func main() {
}
type (
MyCircularDeque struct {
l *list.List
k int
}
Element struct {
Value int
}
)
func Constructor(k int) MyCircularDeque {
return MyCircularDeque{
l: list.New(),
k: k,
}
}
func (this *MyCircularDeque) InsertFront(value int) bool {
if this.l.Len() == this.k {
return false
}
this.l.PushFront(&Element{Value: value})
return true
}
func (this *MyCircularDeque) InsertLast(value int) bool {
if this.l.Len() == this.k {
return false
}
this.l.PushBack(&Element{Value: value})
return true
}
func (this *MyCircularDeque) DeleteFront() bool {
if this.l.Len() == 0 {
return false
}
this.l.Remove(this.l.Front())
return true
}
func (this *MyCircularDeque) DeleteLast() bool {
if this.l.Len() == 0 {
return false
}
this.l.Remove(this.l.Back())
return true
}
func (this *MyCircularDeque) GetFront() int {
if this.l.Len() == 0 {
return -1
}
return this.l.Front().Value.(*Element).Value
}
func (this *MyCircularDeque) GetRear() int {
if this.l.Len() == 0 {
return -1
}
return this.l.Back().Value.(*Element).Value
}
func (this *MyCircularDeque) IsEmpty() bool {
return this.l.Len() == 0
}
func (this *MyCircularDeque) IsFull() bool {
return this.l.Len() == this.k
}
/**
* Your MyCircularDeque object will be instantiated and called as such:
* obj := Constructor(k);
* param_1 := obj.InsertFront(value);
* param_2 := obj.InsertLast(value);
* param_3 := obj.DeleteFront();
* param_4 := obj.DeleteLast();
* param_5 := obj.GetFront();
* param_6 := obj.GetRear();
* param_7 := obj.IsEmpty();
* param_8 := obj.IsFull();
*/