List

package
v0.0.0-...-f9b1802 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(a, b int) int

Types

type ArrayList

type ArrayList[T any] struct {
	// contains filtered or unexported fields
}

ArrayList 结构体用于存储数组列表的元素和大小

func NewArrayList

func NewArrayList[T any](capacity int) *ArrayList[T]

NewArrayList 方法创建一个新的数组列表

func (*ArrayList[T]) Append

func (a *ArrayList[T]) Append(newVal T)

Append a new value to the ArrayList

func (*ArrayList[T]) Clear

func (a *ArrayList[T]) Clear()

Clear 方法清除数组列表的元素并将大小设置为0

func (*ArrayList[T]) Contains

func (a *ArrayList[T]) Contains(val T) bool

Contains 方法返回一个布尔值,指示数组列表是否包含给定的值

func (*ArrayList[T]) Delete

func (a *ArrayList[T]) Delete(index int) error

Delete an element from the ArrayList at a given index

func (*ArrayList[T]) Get

func (a *ArrayList[T]) Get(index int) (T, error)

Get 方法返回数组列表中给定索引的元素

func (*ArrayList[T]) Insert

func (a *ArrayList[T]) Insert(index int, newVal T) error

Insert function inserts a new value into an array list at a given index

func (*ArrayList[T]) IsEmpty

func (a *ArrayList[T]) IsEmpty() bool

IsEmpty 方法返回一个布尔值,指示数组列表是否为空

func (*ArrayList[T]) Set

func (a *ArrayList[T]) Set(index int, newVal T) error

Set function sets a value in an array list at a given index

func (*ArrayList[T]) Size

func (a *ArrayList[T]) Size() int

Size 方法返回数组列表的大小

type LinkedList

type LinkedList[T any] struct {
	// contains filtered or unexported fields
}

LinkedList 采用带头节点的双循环链表

func NewLinkedList

func NewLinkedList[T any]() *LinkedList[T]

NewLinkedList 创建一个LinkedList

func (*LinkedList[T]) Append

func (l *LinkedList[T]) Append(newVal T)

Append 在末尾添加新元素

func (*LinkedList[T]) Clear

func (l *LinkedList[T]) Clear()

Clear 清空链表

func (*LinkedList[T]) Contains

func (l *LinkedList[T]) Contains(val T) bool

Contains 判断链表是否包含这个元素

func (*LinkedList[T]) Delete

func (l *LinkedList[T]) Delete(index int) error

Delete 删除指定位置的值

func (*LinkedList[T]) Get

func (l *LinkedList[T]) Get(index int) (T, error)

Get 根据index获取对应的值

func (*LinkedList[T]) Insert

func (l *LinkedList[T]) Insert(index int, newVal T) error

Insert 在指定位置插入元素

func (*LinkedList[T]) IsEmpty

func (l *LinkedList[T]) IsEmpty() bool

IsEmpty 判断链表是否为空

func (*LinkedList[T]) Set

func (l *LinkedList[T]) Set(index int, newVal T) error

Set 修改目标位置的值

func (*LinkedList[T]) Size

func (l *LinkedList[T]) Size() int

Size 返回链表长度

type List

type List[T any] interface {
	// Size return the length of list
	Size() int

	//IsEmpty return whether the list is empty
	IsEmpty() bool

	//Clear the method which is clear the list
	Clear()

	//Get return the element based on index
	//if it doesn't exist,return nil and error
	//if it does exist,return the element and nil
	Get(index int) (T, error)

	//Contains return the val does exist in this list or not
	Contains(val T) bool

	//Set the element in this list based on index
	//if failed,it will be return an error;
	//if successful, return nil
	Set(index int, newVal T) error

	//Insert an element to this list based on index
	//if failed,return an error
	//if successful,return nil
	Insert(index int, newVal T) error

	//Append a newVal to end of this list
	Append(newVal T)

	//Delete an element in this list based on index
	Delete(index int) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL