sll

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

README

= A generics based Go Singly Linked List

A simple singlely linked list (SLL)  with IsEmpty, AppendSLL, HeadSLL, Length

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptySll = errors.New("Empty Sll")

An error to indicate that the stack is empty

Functions

This section is empty.

Types

type Sll

type Sll[T comparable.Equality] struct {
	// contains filtered or unexported fields
}

Sll is a generic type buildt on top of a slice

func NewSll

func NewSll[T comparable.Equality]() *Sll[T]

Create a new SLL and return it. Complexity is O(1).

func (*Sll[T]) Current

func (ns *Sll[T]) Current(el *SllElement[T], pos int) *SllIter[T]

Current will take the node returned from Search or RevrseSearch

func (ns *Sll[T]) Search( t *T ) (rv *SllElement[T], pos int) {

and allow you to start an iteration process from that point.

func (*Sll[T]) Delete

func (ns *Sll[T]) Delete(it *SllElement[T]) (err error)

func (*Sll[T]) Front

func (ns *Sll[T]) Front() *SllIter[T]

Front will start at the beginning of a list for iteration over list.

func (*Sll[T]) InsertAfterTail

func (ns *Sll[T]) InsertAfterTail(t *T)

InsertAfterTail will append a new node to the end of the list.

func (*Sll[T]) InsertBeforeHead

func (ns *Sll[T]) InsertBeforeHead(t *T)

InsertHeadSLL will append a new node to the end of the list.

func (*Sll[T]) IsEmpty

func (ns *Sll[T]) IsEmpty() bool

------------------------------------------------------------------------------------------------------- IsEmpty will return true if the stack is empty

func (*Sll[T]) Length

func (ns *Sll[T]) Length() int

Length returns the number of elements in the list.

func (*Sll[T]) Peek

func (ns *Sll[T]) Peek() (rv *T, err error)

Peek returns the top element of the stack or an error indicating that the stack is empty.

func (*Sll[T]) Pop

func (ns *Sll[T]) Pop() (rv *T, err error)

Pop will remove the top element from the stack. An error is returned if the stack is empty.

func (*Sll[T]) Push

func (ns *Sll[T]) Push(t *T)

Push will append a new node to the end of the list.

func (*Sll[T]) Search

func (ns *Sll[T]) Search(t *T) (rv *SllElement[T], pos int)

Search — Returns the given element from a linked list. Search is from head to tail. O(n)

func (*Sll[T]) Truncate

func (ns *Sll[T]) Truncate()

Truncate removes all data from the list.

type SllElement

type SllElement[T comparable.Equality] struct {
	// contains filtered or unexported fields
}

A node in the singly linked list

type SllIter

type SllIter[T comparable.Equality] struct {
	// contains filtered or unexported fields
}

An iteration type that allows a for loop to walk the list.

func (*SllIter[T]) Done

func (iter *SllIter[T]) Done() bool

Done returns true if the end of the list has been reached.

func (*SllIter[T]) Next

func (iter *SllIter[T]) Next()

Next advances to the next element in the list.

func (*SllIter[T]) Pos

func (iter *SllIter[T]) Pos() int

Pos returns the current "index" of the elemnt being iterated on. So if the list has 3 elements, a, b, c and we start at the head of the list 'a' will have a Pos() of 0, 'b' will have a Pos() of 1 etc.

func (*SllIter[T]) Value

func (iter *SllIter[T]) Value() *T

Value returns the current data for this element in the list.

Jump to

Keyboard shortcuts

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