Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 1.41 KB

File metadata and controls

60 lines (46 loc) · 1.41 KB

stack

GoDoc License Build Status Report Card GoCover

Simple Golang stack implemented through a linked list

Installation

go get -u github.com/tiny-go/stack

Usage

package main

import (
	"fmt"

	"github.com/tiny-go/stack"
)

func main() {
	var a, b, c = 1, 2, 3

	// init stack
	stk := new(stack.Stack[int])

	// push elements
	stk.Push(a)
	stk.Push(b)
	stk.Push(c)

	// get top element
	fmt.Println(stk.Top()) // 3 true
	fmt.Println(stk.Len()) // 3


	// pop elements
	fmt.Println(stk.Pop()) // 3 true
	fmt.Println(stk.Pop()) // 2 true
	fmt.Println(stk.Pop()) // 1 true
	fmt.Println(stk.Pop()) // 0 false
}