code kata 230817

This commit is contained in:
VicRen
2023-08-17 08:47:54 +08:00
parent 1f72cd98d1
commit 792b2c5d3d
6 changed files with 386 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
package main
type Stack []interface{}
func MakeStack() *Stack {
return &Stack{}
}
func (s Stack) Len() int {
return len(s)
}
func (s Stack) IsEmpty() bool {
return len(s) == 0
}
func (s Stack) Top() interface{} {
if s.IsEmpty() {
return nil
}
return s[len(s)-1]
}
func (s *Stack) Push(item interface{}) {
*s = append(*s, item)
}
func (s *Stack) Pop() interface{} {
if s.IsEmpty() {
return nil
}
ret := (*s)[len(*s)-1]
*s = (*s)[:len(*s)-1]
return ret
}