LinkedList

package
v0.0.0-...-c4df37a Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: MIT Imports: 1 Imported by: 0

README

Linked List

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorEmptyList = errors.New("a list is empty")
)

Functions

This section is empty.

Types

type LinkedList

type LinkedList struct {
	// contains filtered or unexported fields
}

LinkedList is a struct that has pointers to the first and last nodes and also size of a list.

func NewLinkedList

func NewLinkedList() *LinkedList

NewLinkedList builds an empty linked list and returns its pointer.

func (*LinkedList) Append

func (l *LinkedList) Append(value interface{})

Append adds an element to the end of a list.

func (*LinkedList) Count

func (l *LinkedList) Count(value interface{}) int

Count returns a number of times a given value is occurred in a list.

func (*LinkedList) PeekFirst

func (l *LinkedList) PeekFirst() (interface{}, error)

PeekFirst takes first element of a list. If a list is empty returns an error.

func (*LinkedList) PeekLast

func (l *LinkedList) PeekLast() (interface{}, error)

PeekLast takes last element of a list. If a list is empty returns an error.

func (*LinkedList) Prepend

func (l *LinkedList) Prepend(value interface{})

Prepend adds an element to the front of a list.

func (*LinkedList) Size

func (l *LinkedList) Size() int

Size returns the number of nodes in a list.

type Node

type Node struct {
	Value interface{}
	Next  *Node
}

Node is a unit in a linked list, that stores data and a pointer to the next element.

Jump to

Keyboard shortcuts

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