stack

package
v0.0.0-...-38a5715 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package stack asks the student to implement a stack in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Name string
}

Data represents what is being stored on the stack.

type Stack

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

Stack represents a stack of data.

func Make

func Make(cap int) *Stack

Make allows the creation of a stack with an initial capacity for efficiency. Otherwise a stack can be used in its zero value state.

func (*Stack) Count

func (s *Stack) Count() int

Count returns the number of items in the stack.

func (*Stack) Operate

func (s *Stack) Operate(f func(data *Data) error) error

Operate accepts a function that takes data and calls the specified function for every piece of data found. It traverses from the top down through the stack.

func (*Stack) Peek

func (s *Stack) Peek(level int) (*Data, error)

Peek provides the data stored on the stack based on the level from the bottom. A value of 0 would return the top piece of data.

func (*Stack) Pop

func (s *Stack) Pop() (*Data, error)

Pop removes data from the top of the stack.

func (*Stack) Push

func (s *Stack) Push(data *Data)

Push adds data into the top of the stack.

Jump to

Keyboard shortcuts

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