51 lines
839 B
Go
51 lines
839 B
Go
package q5
|
|
|
|
type ListHead struct {
|
|
next *ListHead
|
|
prev *ListHead
|
|
data interface{}
|
|
}
|
|
|
|
func (this *ListHead) Init() {
|
|
this.next = this
|
|
this.prev = this
|
|
this.data = nil
|
|
}
|
|
|
|
func (this *ListHead) Del() {
|
|
this.next.prev = this.prev
|
|
this.prev.next = this.next
|
|
this.Init()
|
|
}
|
|
|
|
func (this *ListHead) AddTail(pnew *ListHead) {
|
|
tmp_prev := this.prev
|
|
this.prev = pnew
|
|
pnew.next = this
|
|
pnew.prev = tmp_prev
|
|
tmp_prev.next = pnew
|
|
}
|
|
|
|
func (this *ListHead) FirstEntry() interface{} {
|
|
return this.next.data
|
|
}
|
|
|
|
func (this *ListHead) Replace(pnew *ListHead) {
|
|
pnew.next = this.next
|
|
pnew.next.prev = pnew
|
|
pnew.prev = this.prev
|
|
pnew.data = this.data
|
|
}
|
|
|
|
func (this *ListHead) ReplaceInit(pnew *ListHead) {
|
|
this.Replace(pnew)
|
|
this.Init()
|
|
}
|
|
|
|
func (this *ListHead) Empty() bool {
|
|
return this.next == this
|
|
}
|
|
|
|
func (this *ListHead) DelInit() {
|
|
}
|