list

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package list implements Singly Linked List.

Example
package main

import (
	"fmt"
	"slices"

	"codeberg.org/kurth4cker/go-sample/list"
)

func main() {
	lst := list.List[int]{}
	for i := range 4 {
		lst.Push(i)
	}

	numbers := slices.Collect(lst.All())
	fmt.Println(numbers)
}
Output:

[3 2 1 0]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

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

Singly Linked List implementation. The zero value for a List is an empty List ready to use.

func (*List[T]) All

func (l *List[T]) All() iter.Seq[T]

Returns all elements in list.

func (*List[T]) Pop added in v0.12.0

func (l *List[T]) Pop() (T, bool)

Return and discard head of list.

If head exist, return it and true; otherwise return zero value of type T and false.

func (*List[T]) Push

func (l *List[T]) Push(v T)

Push given item to head of List.

type Node added in v0.12.0

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

Node implements Singly Linked List Node.

Jump to

Keyboard shortcuts

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