代码拉取完成,页面将自动刷新
package main
import "fmt"
type node struct {
val int
pre, nex *node
}
type MyCircularDeque struct {
cap, size int
head, rear *node
}
func Constructor(k int) MyCircularDeque {
head, rear := &node{}, &node{}
head.nex = rear
rear.pre = head
return MyCircularDeque{
cap: k,
head: head,
rear: rear,
}
}
func (this *MyCircularDeque) InsertFront(value int) bool {
if this.size == this.cap {
return false
} else {
node := node{
val: value,
}
nex := this.head.nex
this.head.nex, node.pre, node.nex, nex.pre = &node, this.head, nex, &node
this.size++
return true
}
}
func (this *MyCircularDeque) InsertLast(value int) bool {
if this.size == this.cap {
return false
} else {
node := node{
val: value,
}
fmt.Println(this.rear)
pre := this.rear.pre
this.rear.pre, node.pre, node.nex, pre.nex = &node, pre, this.rear, &node
this.size++
return true
}
}
func (this *MyCircularDeque) DeleteFront() bool {
if this.size == 0 {
return false
} else {
this.head.nex, this.head.nex.nex.pre = this.head.nex.nex, this.head
this.size--
return true
}
}
func (this *MyCircularDeque) DeleteLast() bool {
if this.size == 0 {
return false
} else {
this.rear.pre, this.rear.pre.pre.nex = this.rear.pre.pre, this.rear
this.size--
return true
}
}
func (this *MyCircularDeque) GetFront() int {
if this.size == 0 {
return -1
} else {
return this.head.nex.val
}
}
func (this *MyCircularDeque) GetRear() int {
if this.size == 0 {
return -1
} else {
return this.rear.pre.val
}
}
func (this *MyCircularDeque) IsEmpty() bool {
return this.size == 0
}
func (this *MyCircularDeque) IsFull() bool {
return this.size == this.cap
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。