stack

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MIT Imports: 1 Imported by: 0

README

Go Reference Go Report Card

stack

import "github.com/bruceesmith/stack"

Package stack defines goroutine-safe methods for manipulating a generic stack data structure via the standard operations IsEmpty, Peek, Pop, Push and Size.

Index

type Stack

Stack is a Go stack implementation using a linked list It is go-routine safe

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

func New
func New[T any]() *Stack[T]

New creates an empty Stack

func (*Stack[T]) IsEmpty
func (s *Stack[T]) IsEmpty() bool

IsEmpty returns true if the stack has no elements

func (*Stack[T]) Peek
func (s *Stack[T]) Peek() (value T, ok bool)

Peek returns a copy of the top element off the stack

func (*Stack[T]) Pop
func (s *Stack[T]) Pop() (value T, ok bool)

Pop removes the top element and returns it

func (*Stack[T]) Push
func (s *Stack[T]) Push(v T)

Push adds an element to the top of the stack

func (*Stack[T]) Size
func (s *Stack[T]) Size() int

Size returns the number of elements on the stack

Generated by gomarkdoc

Documentation

Overview

Package stack defines goroutine-safe methods for manipulating a generic stack data structure via the standard operations IsEmpty, Peek, Pop, Push and Size.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

Stack is a Go stack implementation using a linked list It is go-routine safe

func New added in v1.1.0

func New[T any]() *Stack[T]

New creates an empty Stack

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

IsEmpty returns true if the stack has no elements

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (value T, ok bool)

Peek returns a copy of the top element off the stack

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (value T, ok bool)

Pop removes the top element and returns it

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

Push adds an element to the top of the stack

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

Size returns the number of elements on the stack

Jump to

Keyboard shortcuts

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