Challenge: Make a Stack with Variable Internal Types

This lesson brings you a challenge to solve.

We'll cover the following

Problem statement

In the last chapter, we developed some Stack struct-types. However, they were limited to a certain fixed internal type. Now, develop a general stack type using a slice. That slice should be holding elements of type interface{ }. Implement the following stack-methods: Len() int, IsEmpty() bool, Push(x interface{}) and Pop()(x interface{}, error).

Pop() returns the top most element and removes it from the stack. Also, write a method Top(), which only returns this element and does not remove it. Note that the stack will be implemented in the file mystack.go, and its functions will be called in main.go.

Try to solve the challenge below. Good Luck!

Get hands-on with 1200+ tech skills courses.