stack

package
v2.0.0-...-8dcd6a7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2015 License: BSD-2-Clause Imports: 0 Imported by: 7

Documentation

Overview

Package stack implements a LIFO (last in first out) data structure supporting arbitrary types (even a mixture).

Internally it uses a dynamically growing slice of blocks, resulting in faster resizes than a simple dynamic array/slice would allow.

Example (Usage)

Simple usage example that inserts the numbers 1, 2, 3 into a stack and then removes them one by one, printing them to the standard output.

package main

import (
	"fmt"

	"gopkg.in/karalabe/cookiejar.v2/collections/stack"
)

func main() {
	// Create a stack and push some data in
	s := stack.New()
	for i := 0; i < 3; i++ {
		s.Push(i)
	}
	// Pop out the stack contents and display them
	for !s.Empty() {
		fmt.Println(s.Pop())
	}
}
Output:

2
1
0

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

Last in, first out data structure.

func New

func New() *Stack

Creates a new, empty stack.

func (*Stack) Empty

func (s *Stack) Empty() bool

Checks whether the stack is empty or not.

func (*Stack) Pop

func (s *Stack) Pop() (res interface{})

Pops a value off the stack and returns it. Currently no shrinking is done.

func (*Stack) Push

func (s *Stack) Push(data interface{})

Pushes a value onto the stack, expanding it if necessary.

func (*Stack) Reset

func (s *Stack) Reset()

Resets the stack, effectively clearing its contents.

func (*Stack) Size

func (s *Stack) Size() int

Returns the number of elements in the stack.

func (*Stack) Top

func (s *Stack) Top() interface{}

Returns the value currently on the top of the stack. No bounds are checked.

Jump to

Keyboard shortcuts

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