By Golang
// Package stack creates a ItemStack data structure for the Item typepackage stackimport ( "sync")// Item the type of the stacktype Item interface{}// ItemStack the stack of Itemstype ItemStack struct { items []Item lock sync.RWMutex}// New creates a new ItemStackfunc (s *ItemStack) New() *ItemStack { s.items = []Item{} return s}// Push adds an Item to the top of the stackfunc (s *ItemStack) Push(t Item) { s.lock.Lock() s.items = append(s.items, t) s.lock.Unlock()}// Pop removes an Item from the top of the stackfunc (s *ItemStack) Pop() *Item { s.lock.Lock() item := s.items[len(s.items)-1] s.items = s.items[0 : len(s.items)-1] s.lock.Unlock() return &item}