Implement a stack structure with pop, append, and print top functionalities.
Solution
You can implement a stack using a slice object.
package main
import "fmt"
func main() {
// Create
var stack []string
Run
First, we use the built-in append() function to implement the append behavior. Then we use len(stack)-1 to select the top of the stack and print.
For pop, we set the new length of the stack to the position of the printed top value, len(stack)-1.