代码拉取完成,页面将自动刷新
package list
import (
C "gitee.com/ljfirst/algo-go-sdk/common/constant"
)
/**
* @author ljfirst
* @version V1.0
* @date 2023/6/28 17:03
* @author-Email ljfirst@mail.ustc.edu.cn
* @blogURL https://blog.csdn.net/ljfirst
* @description
* */
type DuplexList struct {
head *Node // 带有头节点的list
tail *Node
size int
headInsert bool // 头插法,默认false是尾插法
}
func NewDuplexList(options ...C.Options) *DuplexList {
opt := C.NewOptions(options...)
temp := &Node{}
list := &DuplexList{
head: temp,
tail: temp,
size: 0,
}
list.headInsert = opt.HeadInsert
return list
}
func (m *DuplexList) Insert(node ...*Node) { // 尾插入
if node == nil || len(node) == 0 {
return
}
if m.headInsert {
for i := 0; i < len(node); i++ {
node[i].Next = m.head.Next
m.head.Next = node[i]
}
// 链表为空时的首个元素处理
if m.head.Next == nil {
m.tail = node[0]
}
return
}
// 尾插法
for i := 0; i < len(node); i++ {
m.tail.Next = node[i]
m.tail = node[i]
}
}
func (m *DuplexList) InsertIndex(index int, nodes ...*Node) { // index 起始为0
for _, n := range nodes {
node := n
if node == nil {
return
}
// 空链表插入首个节点
if index == 0 && m.head == nil {
m.Insert(node)
return
}
// 插入首个节点
if index == 0 {
}
if index >= m.size {
return
}
count := 0
point := m.head
for count < index {
point = point.Next
count++
}
if point.Next != nil {
next := point.Next
next.Pre = node
node.Next = next
}
point.Next = node
node.Pre = point
}
}
func (m *DuplexList) Delete(node *Node) {}
func (m *DuplexList) DeleteIndex(int) {}
func (m *DuplexList) ValueSet() []interface{} {
return nil
}
func (m *DuplexList) Equals(node *Node) {}
func (m *DuplexList) Size() int { return 0 }
func (m *DuplexList) Clear() {}
func (m *DuplexList) GetAttribute() *C.Attribute {
return &C.Attribute{
Tags: []string{C.List},
Desc: &C.Desc{
Name: "DuplexList",
NameCn: "双向链表",
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。