package mainimport "fmt"type Stack struct { elements []int}// Push: 요소 추가func (s *Stack) Push(value int) { s.elements = append(s.elements, value)}// Pop: 스택에서 요소 제거 및 반환func (s *Stack) Pop() (int, bool) { // 스택이 비어있는 경우 if len(s.elements) == 0 { return 0, false } // 맨 위 요소 저장 value := s.elements[len(s.elements)-1] // 맨 위 요소 제거 s.elements = s.elements[:len(s.elements)-1] return value, true}// Peek: 맨 위 요소 확인func (s *Stack) Peek() (int, bool) { if len(s.elements) == 0 { return 0, false // 스택이 비어있는 경우 } return s.elements[len(s.elements)-1], true}// IsEmpty: 스택이 비어있는지 확인func (s *Stack) IsEmpty() bool { return len(s.elements) == 0}func main() { s := Stack{} s.Push(1) s.Push(2) s.Push(3) fmt.Println("Stack Status", s.elements) if top, ok := s.Peek(); ok { fmt.Println("Peek:", top) } for !s.IsEmpty() { value, _ := s.Pop() fmt.Println("Pop:", value) } fmt.Println("Is stack empty?", s.IsEmpty())}