Skip to content

Latest commit

 

History

History
91 lines (66 loc) · 1.91 KB

README.md

File metadata and controls

91 lines (66 loc) · 1.91 KB

One-Way Linked-List Go

This is a simple implementation of a one-way linked-list in Go. The one way linkedlist is a data structure that is made up of nodes. Each node contains a value and a pointer to the next node. The head of the list is the first node in the list. The tail of the list is the last node in the list. The tail of the list points to nil.

Structure

Types:

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

type List struct {
	Head *Node
}

Methods:

// Create, O(1)
func (list *List) Create(value interface{})

// InsertBegin, O(1)
func (list *List) InsertBegin(value interface{})

// InsertEnd, O(n)
func (list *List) InsertEnd(value interface{})

// InsertAfter, O(n)
func (list *List) InsertAfter(value interface{}, after interface{})

// InsertBefore, O(n)
func (list *List) InsertBefore(value interface{}, before interface{})

// DeleteBegin, O(1)
func (list *List) DeleteBegin()

// DeleteEnd, O(n)
func (list *List) DeleteEnd()

// DeleteValue, O(n)
func (list *List) DeleteValue(value interface{})

// DeleteAfterValue, O(n)
func (list *List) DeleteAfterValue(value interface{})

// DeleteBeforeValue, O(n)
func (list *List) DeleteBeforeValue(value interface{})

// DeleteIndex, O(n)
func (list *List) DeleteIndex(index int)

// DeleteAfterIndex, O(n)
func (list *List) DeleteAfterIndex(index int)

// DeleteBeforeIndex, O(n)
func (list *List) DeleteBeforeIndex(index int)

// Search, O(n)
func (list *List) Search(value interface{}) bool

// Print, O(n)
func (list *List) Print()

// ToString, O(n)
func (list *List) ToString() string

© Copyright 2022, Max Base