Solution Review: Make a Stack with Variable Internal Types
This lesson discusses the solution to the challenge given in the previous lesson.
We'll cover the following...
package main import ( "fmt" "mystack" ) var st1 mystack.Stack func main() { st1.Push("Brown") st1.Push(3.14) st1.Push(100) st1.Push([]string{"Java", "C++", "Python", "C#", "Ruby"}) for { item, err := st1.Pop() if err != nil { break } fmt.Println(item) } }
In this program, we develop a generic stack
type using a slice holding elements of type interface{ }
. This is done in ...