packagediffmatchpatchimport("fmt")typeStackstruct{top*Elementsizeint}typeElementstruct{valueinterface{}next*Element}// Len returns the stack's lengthfunc(s*Stack)Len()int{returns.size}// Push appends a new element onto the stackfunc(s*Stack)Push(valueinterface{}){s.top=&Element{value,s.top}s.size++}// Pop removes the top element from the stack and return its value// If the stack is empty, return nilfunc(s*Stack)Pop()(valueinterface{}){ifs.size>0{value,s.top=s.top.value,s.top.nexts.size--return}returnnil}// Peek returns the value of the element on the top of the stack// but don't remove it. If the stack is empty, return nilfunc(s*Stack)Peek()(valueinterface{}){ifs.size>0{value=s.top.valuereturn}return-1}// Clear empties the stackfunc(s*Stack)Clear(){s.top=nils.size=0}funcmain(){stack:=new(Stack)stack.Push("Things")stack.Push("and")stack.Push("Stuff")forstack.Len()>0{fmt.Printf("%s ",stack.Pop().(string))}fmt.Println()}