stack

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 0 Imported by: 0

README

personal-go-modules

个人编写并使用的 Golang Modules仓库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

type Stack[T any] struct {
	Items []T
	Top   int
}

定义一个泛型的Stack结构体

func NewStack

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

func (*Stack[T]) IsEmpty

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

实现IsEmpty方法来检查栈是否为空

func (*Stack[T]) Peek

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

实现Peek方法来查看栈顶元素但不移除它

func (*Stack[T]) Pop

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

实现Pop方法来移除并返回栈顶元素

func (*Stack[T]) Push

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

实现Push方法来添加元素

Jump to

Keyboard shortcuts

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