Documentation ¶
Overview ¶
A stack is a fundamental data structure which is extensively used. This package provides a basic implementation of a stack in Go. A stack works using Last In First Out (LIFO) method.
Example ¶
package main import ( "fmt" "go.ajitem.com/stack" ) func main() { s := stack.New() s.Push(1) s.Push(2) s.Push(3) s.Push(4) fmt.Println("size:", s.Size()) number, _ := s.Pop() fmt.Println("number:", number) number, _ = s.Pop() fmt.Println("number:", number) number, _ = s.Pop() fmt.Println("number:", number) fmt.Println("size:", s.Size()) number, _ = s.Peek() fmt.Println("number:", number) }
Output: size: 4 number: 4 number: 3 number: 2 size: 1 number: 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var IsEmpty = errors.New("stack is empty")
IsEmpty is the error returned by the stack when no elements are present in the stack
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.