How to Implement a Stack in Go

Implement a stack in Go using a struct with a slice and Push/Pop methods for LIFO operations.

Implement a stack in Go by defining a struct with a slice and adding Push and Pop methods to manage the data.

type Stack struct {
	items []int
}

func (s *Stack) Push(item int) {
	s.items = append(s.items, item)
}

func (s *Stack) Pop() (int, bool) {
	if len(s.items) == 0 {
		return 0, false
	}
	index := len(s.items) - 1
	item := s.items[index]
	s.items = s.items[:index]
	return item, true
}