1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2022-05-20 17:31:42 +08:00
parent ed02794b04
commit a5cc6eb04c

View File

@ -1,2 +1,38 @@
package collections package collections
type Item[T any] interface {
Less(T) bool
}
// 单链表节点
type linkedNode[T Item[T]] struct {
item T
next *linkedNode[T]
}
// 双向链接节点
type doubleLinkedNode[T Item[T]] struct {
item T
prev *linkedNode[T]
next *linkedNode[T]
}
type LinkedList[T Item[T]] struct {
head, tail *linkedNode[T]
size int
}
// 初始化单向链表
func NewLinkedList[T Item[T]]() *LinkedList[T] {
return &LinkedList[T]{}
}
type DLinkedList[T Item[T]] struct {
head, tail *doubleLinkedNode[T]
size int
}
// 初始化双向链表
func NewDoubleLinkedLis[T Item[T]]() *DLinkedList[T] {
return &DLinkedList[T]{}
}